Skip to content

Commit

Permalink
Merge pull request SciTools#2401 from e-k-m/main
Browse files Browse the repository at this point in the history
Fix failing gouraud shading mask creation in pccolormesh
  • Loading branch information
greglucas committed Jun 22, 2024
2 parents 4e104fc + 9c5f129 commit 300c8b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ def _wrap_quadmesh(self, collection, **kwargs):
"It is recommended to remove the wrap manually "
"before calling pcolormesh.")
# With gouraud shading, we actually want an (Ny, Nx) shaped mask
gmask = np.zeros(data_shape, dtype=bool)
gmask = np.zeros((data_shape[0], data_shape[1]), dtype=bool)
# If any of the cells were wrapped, apply it to all 4 corners
gmask[:-1, :-1] |= mask
gmask[1:, :-1] |= mask
Expand Down
11 changes: 11 additions & 0 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,17 @@ def test_pcolormesh_single_column_wrap():
return fig


def test_pcolormesh_wrap_gouraud_shading_failing_mask_creation():
x_range = np.linspace(-180, 180, 50)
y_range = np.linspace(90, -90, 50)
x, y = np.meshgrid(x_range, y_range)
data = ((np.sin(np.deg2rad(x))) / 10. + np.exp(np.cos(np.deg2rad(y))))

fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mercator())
ax.pcolormesh(x, y, data, transform=ccrs.PlateCarree(), shading='gouraud')


def test_pcolormesh_diagonal_wrap():
# Check that a cell with the top edge on one side of the domain
# and the bottom edge on the other gets wrapped properly
Expand Down

0 comments on commit 300c8b1

Please sign in to comment.