8000 Merge pull request #26234 from meeseeksmachine/auto-backport-of-pr-26… · matplotlib/matplotlib@4e086d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e086d3

Browse files
authored
Merge pull request #26234 from meeseeksmachine/auto-backport-of-pr-26232-on-v3.7.x
Backport PR #26232 on branch v3.7.x (FIX: pcolor writing to read-only input mask)
2 parents 0a5c4b5 + df8c950 commit 4e086d3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5708,7 +5708,7 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
57085708
# unit conversion allows e.g. datetime objects as axis values
57095709
X, Y = args[:2]
57105710
X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
5711-
X, Y = [cbook.safe_masked_invalid(a) for a in [X, Y]]
5711+
X, Y = [cbook.safe_masked_invalid(a, copy=True) for a in [X, Y]]
57125712

57135713
if funcname == 'pcolormesh':
57145714
if np.ma.is_masked(X) or np.ma.is_masked(Y):

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,11 +1429,17 @@ def test_pcolorargs_with_read_only():
14291429
y = np.linspace(0, 1, 10)
14301430
X, Y = np.meshgrid(x, y)
14311431
Z = np.sin(2 * np.pi * X) * np.cos(2 * np.pi * Y)
1432-
Zmask = np.broadcast_to([True, False] * 5, Z.shape)
1433-
assert Zmask.flags.writeable is False
1434-
masked_Z = np.ma.array(Z, mask=Zmask)
1432+
mask = np.broadcast_to([True, False] * 5, Z.shape)
1433+
assert mask.flags.writeable is False
1434+
masked_Z = np.ma.array(Z, mask=mask)
14351435
plt.pcolormesh(X, Y, masked_Z)
14361436

1437+
masked_X = np.ma.array(X, mask=mask)
1438+
masked_Y = np.ma.array(Y, mask=mask)
1439+
with pytest.warns(UserWarning,
1440+
match='are not monotonically increasing or decreasing'):
1441+
plt.pcolor(masked_X, masked_Y, masked_Z)
1442+
14371443

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

0 commit comments

Comments
 (0)
0