Skip to content

Commit

Permalink
Merge pull request #2426 from rcomer/pcolormesh-shading
Browse files Browse the repository at this point in the history
Support shading=None in pcolor(mesh)
  • Loading branch information
dopplershift authored Aug 23, 2024
2 parents c86f49f + d1d3863 commit 75939f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75939f9

Please sign in to comment.