Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ad27c9e

Browse filesBrowse files
authored
Merge pull request #20578 from meeseeksmachine/auto-backport-of-pr-20511-on-v3.4.x
Backport PR #20511 on branch v3.4.x (Fix calls to np.ma.masked_where)
2 parents 56269d8 + 1626281 commit ad27c9e
Copy full SHA for ad27c9e

File tree

4 files changed

+46
-5
lines changed
Filter options

4 files changed

+46
-5
lines changed

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,11 +1535,11 @@ class LogNorm(Normalize):
15351535

15361536
def autoscale(self, A):
15371537
# docstring inherited.
1538-
super().autoscale(np.ma.masked_less_equal(A, 0, copy=False))
1538+
super().autoscale(np.ma.array(A, mask=(A <= 0)))
15391539

15401540
def autoscale_None(self, A):
15411541
# docstring inherited.
1542-
super().autoscale_None(np.ma.masked_less_equal(A, 0, copy=False))
1542+
super().autoscale_None(np.ma.array(A, mask=(A <= 0)))
15431543

15441544

15451545
@_make_norm_from_scale(

‎lib/matplotlib/quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/quiver.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,10 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
11471147
return barb_list
11481148

11491149
def set_UVC(self, U, V, C=None):
1150-
self.u = ma.masked_invalid(U, copy=False).ravel()
1151-
self.v = ma.masked_invalid(V, copy=False).ravel()
1150+
# We need to ensure we have a copy, not a reference to an array that
1151+
# might change before draw().
1152+
self.u = ma.masked_invalid(U, copy=True).ravel()
1153+
self.v = ma.masked_invalid(V, copy=True).ravel()
11521154

11531155
# Flip needs to have the same number of entries as everything else.
11541156
# Use broadcast_to to avoid a bloated array of identical values.
@@ -1159,7 +1161,7 @@ def set_UVC(self, U, V, C=None):
11591161
flip = self.flip
11601162

11611163
if C is not None:
1162-
c = ma.masked_invalid(C, copy=False).ravel()
1164+
c = ma.masked_invalid(C, copy=True).ravel()
11631165
x, y, u, v, c, flip = cbook.delete_masked_points(
11641166
self.x.ravel(), self.y.ravel(), self.u, self.v, c,
11651167
flip.ravel())

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,34 @@ def test_imshow_quantitynd():
12131213
fig.canvas.draw()
12141214

12151215

1216+
@check_figures_equal(extensions=['png'])
1217+
def test_norm_change(fig_test, fig_ref):
1218+
# LogNorm should not mask anything invalid permanently.
1219+
data = np.full((5, 5), 1, dtype=np.float64)
1220+
data[0:2, :] = -1
1221+
1222+
masked_data = np.ma.array(data, mask=False)
1223+
masked_data.mask[0:2, 0:2] = True
1224+
1225+
cmap = plt.get_cmap('viridis').with_extremes(under='w')
1226+
1227+
ax = fig_test.subplots()
1228+
im = ax.imshow(data, norm=colors.LogNorm(vmin=0.5, vmax=1),
1229+
extent=(0, 5, 0, 5), interpolation='nearest', cmap=cmap)
1230+
im.set_norm(colors.Normalize(vmin=-2, vmax=2))
1231+
im = ax.imshow(masked_data, norm=colors.LogNorm(vmin=0.5, vmax=1),
1232+
extent=(5, 10, 5, 10), interpolation='nearest', cmap=cmap)
1233+
im.set_norm(colors.Normalize(vmin=-2, vmax=2))
1234+
ax.set(xlim=(0, 10), ylim=(0, 10))
1235+
1236+
ax = fig_ref.subplots()
1237+
ax.imshow(data, norm=colors.Normalize(vmin=-2, vmax=2),
1238+
extent=(0, 5, 0, 5), interpolation='nearest', cmap=cmap)
1239+
ax.imshow(masked_data, norm=colors.Normalize(vmin=-2, vmax=2),
1240+
extent=(5, 10, 5, 10), interpolation='nearest', cmap=cmap)
1241+
ax.set(xlim=(0, 10), ylim=(0, 10))
1242+
1243+
12161244
@pytest.mark.parametrize('x', [-1, 1])
12171245
@check_figures_equal(extensions=['png'])
12181246
def test_huge_range_log(fig_test, fig_ref, x):

‎lib/matplotlib/tests/test_quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_quiver.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ def test_barbs_flip():
202202
flip_barb=Y < 0)
203203

204204

205+
def test_barb_copy():
206+
fig, ax = plt.subplots()
207+
u = np.array([1.1])
208+
v = np.array([2.2])
209+
b0 = ax.barbs([1], [1], u, v)
210+
u[0] = 0
211+
assert b0.u[0] == 1.1
212+
v[0] = 0
213+
assert b0.v[0] == 2.2
214+
215+
205216
def test_bad_masked_sizes():
206217
"""Test error handling when given differing sized masked arrays."""
207218
x = np.arange(3)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.