Skip to content

Commit

Permalink
FIX: imshow arguments should be popped before passing upstream
Browse files Browse the repository at this point in the history
We have extra keyword arguments in Cartopy that can't be passed
upstream to Matplotlib, so remove them from the keyword arguments
before going into any possible methods.
  • Loading branch information
greglucas committed Jul 11, 2024
1 parent ca2832e commit 98834c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,9 @@ def imshow(self, img, *args, **kwargs):
x0 - eps <= extent[1] <= x1 + eps and
y0 - eps <= extent[2] <= y1 + eps and
y0 - eps <= extent[3] <= y1 + eps))

# Make sure we are popping the regrid_shape before calling any
# upstream imshow methods.
regrid_shape = kwargs.pop('regrid_shape', 750)
if (transform is None or transform == self.transData or
same_projection and inside_bounds):
result = super().imshow(img, *args, **kwargs)
Expand All @@ -1298,7 +1300,6 @@ def imshow(self, img, *args, **kwargs):
'handle a %s in imshow.' % type(transform))

target_extent = self.get_extent(self.projection)
regrid_shape = kwargs.pop('regrid_shape', 750)
regrid_shape = self._regrid_shape_aspect(regrid_shape,
target_extent)
# Lazy import because scipy/pykdtree in img_transform are only
Expand Down
11 changes: 11 additions & 0 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def test_imshow_wrapping():
assert ax.get_xlim() == (-180, 180)


def test_imshow_arguments():
"""Smoke test for imshow argument passing in the fast-path"""
ax = plt.axes(projection=ccrs.PlateCarree())
# Set the regrid_shape parameter to ensure it isn't passed to Axes.imshow()
# in the fast-path call to super()
ax.imshow(np.random.random((10, 10)), transform=ccrs.PlateCarree(),
extent=(-180, 180, -90, 90), regrid_shape=500)

assert ax.get_xlim() == (-180, 180)


def test_imshow_rgba():
# tests that the alpha of a RGBA array passed to imshow is set to 0
# instead of masked
Expand Down

0 comments on commit 98834c9

Please sign in to comment.