diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py index b55714a98..5a429dc7b 100644 --- a/lib/cartopy/mpl/geoaxes.py +++ b/lib/cartopy/mpl/geoaxes.py @@ -1790,8 +1790,8 @@ def _wrap_args(self, *args, **kwargs): the data coordinates before passing on to Matplotlib. """ default_shading = mpl.rcParams.get('pcolor.shading') - if not (kwargs.get('shading', default_shading) in - ('nearest', 'auto') and len(args) == 3 and + shading = kwargs.get('shading') or default_shading + if not (shading in ('nearest', 'auto') and len(args) == 3 and getattr(kwargs.get('transform'), '_wrappable', False)): return args, kwargs diff --git a/lib/cartopy/tests/mpl/test_mpl_integration.py b/lib/cartopy/tests/mpl/test_mpl_integration.py index 400be6828..302505d99 100644 --- a/lib/cartopy/tests/mpl/test_mpl_integration.py +++ b/lib/cartopy/tests/mpl/test_mpl_integration.py @@ -773,9 +773,24 @@ def test_pcolormesh_shading(shading, input_size, expected): d = np.zeros((3, 3)) coll = ax.pcolormesh(x, y, d, shading=shading) - # We can use coll.get_coordinates() once MPL >= 3.5 is required - # For now, we use the private variable for testing - assert coll._coordinates.shape == (expected, expected, 2) + assert coll.get_coordinates().shape == (expected, expected, 2) + + +def test__wrap_args_default_shading(): + # Passing shading=None should give the same as not passing the shading parameter. + x = np.linspace(0, 360, 12) + y = np.linspace(0, 90, 5) + z = np.zeros((12, 5)) + + ax = plt.subplot(projection=ccrs.Orthographic()) + args_ref, kwargs_ref = ax._wrap_args(x, y, z, transform=ccrs.PlateCarree()) + args_test, kwargs_test = ax._wrap_args( + x, y, z, transform=ccrs.PlateCarree(), shading=None) + + for array_ref, array_test in zip(args_ref, args_test): + np.testing.assert_allclose(array_ref, array_test) + + assert kwargs_ref == kwargs_test @pytest.mark.natural_earth