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 b3bf734

Browse filesBrowse files
committed
Copy UVC input to Barbs.
For the same reason as Quiver in #4250.
1 parent c6c85e6 commit b3bf734
Copy full SHA for b3bf734

File tree

2 files changed

+16
-3
lines changed
Filter options

2 files changed

+16
-3
lines changed

‎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
@@ -1158,8 +1158,10 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
11581158
return barb_list
11591159

11601160
def set_UVC(self, U, V, C=None):
1161-
self.u = ma.masked_invalid(U, copy=False).ravel()
1162-
self.v = ma.masked_invalid(V, copy=False).ravel()
1161+
# We need to ensure we have a copy, not a reference to an array that
1162+
# might change before draw().
1163+
self.u = ma.masked_invalid(U, copy=True).ravel()
1164+
self.v = ma.masked_invalid(V, copy=True).ravel()
11631165

11641166
# Flip needs to have the same number of entries as everything else.
11651167
# Use broadcast_to to avoid a bloated array of identical values.
@@ -1170,7 +1172,7 @@ def set_UVC(self, U, V, C=None):
11701172
flip = self.flip
11711173

11721174
if C is not None:
1173-
c = ma.masked_invalid(C, copy=False).ravel()
1175+
c = ma.masked_invalid(C, copy=True).ravel()
11741176
x, y, u, v, c, flip = cbook.delete_masked_points(
11751177
self.x.ravel(), self.y.ravel(), self.u, self.v, c,
11761178
flip.ravel())

‎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.