8000 Fix: pcolormesh writing to read-only input mask by Rylie-W · Pull Request #26223 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix: pcolormesh writing to read-only input mask #26223

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
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5764,7 +5764,7 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
else:
X, Y = np.meshgrid(np.arange(ncols + 1), np.arange(nrows + 1))
shading = 'flat'
C = cbook.safe_masked_invalid(C)
C = cbook.safe_masked_invalid(C, copy=True)
return X, Y, C, shading

if len(args) == 3:
Expand Down Expand Up @@ -5853,7 +5853,7 @@ def _interp_grid(X):
Y = _interp_grid(Y.T).T
shading = 'flat'

C = cbook.safe_masked_invalid(C)
C = cbook.safe_masked_invalid(C, copy=True)
return X, Y, C, shading

@_preprocess_data()
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,20 @@ def test_pcolorargs():
match='are not monotonically increasing or decreasing'):
ax.pcolormesh(X, Y, Z, shading='auto')

# GH 26093
x = np.arange(6).reshape(2, 3)
mask = np.broadcast_to([False, True, False], x.shape) # read-only array
masked_x = np.ma.array(x, mask=mask)
plt.pcolormesh(masked_x)

x = np.linspace(0, 1, 10)
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)
masked_Z = np.ma.array(Z, mask=Zmask)
plt.pcolormesh(X, Y, masked_Z)


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