Skip to content

FIX: pcolor writing to read-only input mask #26232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2023
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
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5773,7 +5773,7 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
# unit conversion allows e.g. datetime objects as axis values
X, Y = args[:2]
X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
X, Y = [cbook.safe_masked_invalid(a) for a in [X, Y]]
X, Y = [cbook.safe_masked_invalid(a, copy=True) for a in [X, Y]]

if funcname == 'pcolormesh':
if np.ma.is_masked(X) or np.ma.is_masked(Y):
Expand Down
12 changes: 9 additions & 3 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,11 +1507,17 @@ def test_pcolorargs_with_read_only():
y = np.linspace(0, 1, 10)
X, Y = np.meshgrid(x, y)
Z = np.sin(2 * np.pi * X) * np.cos(2 * np.pi * Y)
Zmask = np.broadcast_to([True, False] * 5, Z.shape)
assert Zmask.flags.writeable is False
masked_Z = np.ma.array(Z, mask=Zmask)
mask = np.broadcast_to([True, False] * 5, Z.shape)
assert mask.flags.writeable is False
masked_Z = np.ma.array(Z, mask=mask)
plt.pcolormesh(X, Y, masked_Z)

masked_X = np.ma.array(X, mask=mask)
masked_Y = np.ma.array(Y, mask=mask)
with pytest.warns(UserWarning,
match='are not monotonically increasing or decreasing'):
plt.pcolor(masked_X, masked_Y, masked_Z)


@check_figures_equal(extensions=["png"])
def test_pcolornearest(fig_test, fig_ref):
Expand Down