Skip to content

Commit

Permalink
Merge pull request SciTools#1712 from greglucas/contour_bounds
Browse files Browse the repository at this point in the history
Update contour extents
  • Loading branch information
QuLogic authored Jan 18, 2021
2 parents 4119741 + 2a5b90d commit 57791d4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,14 @@ def contour(self, *args, **kwargs):
"""
result = matplotlib.axes.Axes.contour(self, *args, **kwargs)

# We need to compute the dataLim correctly for contours.
bboxes = [col.get_datalim(self.transData)
for col in result.collections
if col.get_paths()]
if bboxes:
extent = mtransforms.Bbox.union(bboxes)
self.dataLim.update_from_data_xy(extent.get_points())

self.autoscale_view()

# Re-cast the contour as a GeoContourSet.
Expand Down
1 change: 0 additions & 1 deletion lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def _draw_gridliner(self, nx=None, ny=None, renderer=None):
sup = min(lat_lim[1], crs.y_limits[1])
lat_ticks = [value for value in lat_ticks if inf <= value <= sup]


#####################
# Gridlines drawing #
#####################
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lib/cartopy/tests/mpl/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ def test_contour_linear_ring():
ax.contourf(lons, lats, vals, np.arange(9), transform=ccrs.PlateCarree())

plt.draw()


def test_contour_update_bounds():
"""Test that contour updates the extent"""
xs, ys = np.meshgrid(np.linspace(0, 360), np.linspace(-80, 80))
zs = ys**2
ax = plt.axes(projection=ccrs.Orthographic())
ax.contour(xs, ys, zs, transform=ccrs.PlateCarree())
# Force a draw, which is a smoke test to make sure contouring
# doesn't raise with an Orthographic projection
# GH issue 1673
plt.draw()
8 changes: 8 additions & 0 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_global_contour_wrap_new_transform():
x, y = np.meshgrid(np.linspace(0, 360), np.linspace(-90, 90))
data = np.sin(np.sqrt(x ** 2 + y ** 2))
plt.contour(x, y, data, transform=ccrs.PlateCarree())
if MPL_VERSION <= '3.0.0':
# Rather than updating image test for old version
# Remove when only MPL > 3 is required
ax.set_extent((-176.3265306122449, 176.3265306122449, -90.0, 90.0))


@pytest.mark.natural_earth
Expand All @@ -55,6 +59,10 @@ def test_global_contour_wrap_no_transform():
x, y = np.meshgrid(np.linspace(0, 360), np.linspace(-90, 90))
data = np.sin(np.sqrt(x ** 2 + y ** 2))
plt.contour(x, y, data)
if MPL_VERSION <= '3.0.0':
# Rather than updating image test for old version
# Remove when only MPL > 3 is required
ax.set_extent((-176.3265306122449, 176.3265306122449, -90.0, 90.0))


@pytest.mark.natural_earth
Expand Down
2 changes: 2 additions & 0 deletions lib/cartopy/tests/mpl/test_ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def _format_lon(val, i):


ticks_tolerance = 7


@pytest.mark.natural_earth
@ImageTesting(['xticks_no_transform'],
tolerance=ticks_tolerance)
Expand Down

0 comments on commit 57791d4

Please sign in to comment.