Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1880,10 +1880,8 @@ def _pcolormesh_patched(self, *args, **kwargs):
C_mask = getattr(C, 'mask', None)

# create the masked array to be used with this pcolormesh
if C_mask is not None:
pcolormesh_data = np.ma.array(C, mask=mask | C_mask)
else:
pcolormesh_data = np.ma.array(C, mask=mask)
full_mask = mask if C_mask is None else mask | C_mask
pcolormesh_data = np.ma.array(C, mask=full_mask)

collection.set_array(pcolormesh_data.ravel())

Expand All @@ -1901,16 +1899,22 @@ def _pcolormesh_patched(self, *args, **kwargs):
# We will add the original data mask in later to
# make sure that set_array can work in future
# calls on the proper sized array inputs.
pcolor_data = np.ma.array(C.data, mask=~mask)
# NOTE: we don't use C.data here because C.data could
# contain nan's which would be masked in the
# pcolor routines, which we don't want. We will
# fill in the proper data later with set_array()
# calls.
pcolor_data = np.ma.array(np.zeros(C.shape),
mask=~mask)
pcolor_col = self.pcolor(pts[..., 0], pts[..., 1],
pcolor_data, zorder=zorder,
**kwargs)
# Now add back in the masked data if there was any
if C_mask is not None:
pcolor_data = np.ma.array(C, mask=~mask | C_mask)
# The pcolor_col is now possibly shorter than the
# actual collection, so grab the masked cells
pcolor_col.set_array(pcolor_data[mask].ravel())
full_mask = ~mask if C_mask is None else ~mask | C_mask
pcolor_data = np.ma.array(C, mask=full_mask)
# The pcolor_col is now possibly shorter than the
# actual collection, so grab the masked cells
pcolor_col.set_array(pcolor_data[mask].ravel())
pcolor_col.set_cmap(cmap)
pcolor_col.set_norm(norm)
pcolor_col.set_clim(vmin, vmax)
Expand Down
13 changes: 13 additions & 0 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ def test_pcolormesh_diagonal_wrap():
assert hasattr(mesh, "_wrapped_collection_fix")


def test_pcolormesh_nan_wrap():
# Check that data with nan's as input still creates
# the proper number of pcolor cells and those aren't
# masked in the process.
xs, ys = np.meshgrid([120, 160, 200], [-30, 0, 30])
data = np.ones((2, 2)) * np.nan

ax = plt.axes(projection=ccrs.PlateCarree())
mesh = ax.pcolormesh(xs, ys, data)
pcolor = getattr(mesh, "_wrapped_collection_fix")
assert len(pcolor.get_paths()) == 2


@pytest.mark.natural_earth
@ImageTesting(['pcolormesh_goode_wrap'])
def test_pcolormesh_goode_wrap():
Expand Down