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 bae1eff

Browse filesBrowse files
committed
BUG: Quiver must copy U, V, C args so they can't change before draw()
1 parent 71ba6ff commit bae1eff
Copy full SHA for bae1eff

File tree

Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-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
@@ -529,11 +529,13 @@ def draw(self, renderer):
529529
mcollections.PolyCollection.draw(self, renderer)
530530

531531
def set_UVC(self, U, V, C=None):
532-
U = ma.masked_invalid(U, copy=False).ravel()
533-
V = ma.masked_invalid(V, copy=False).ravel()
532+
# We need to ensure we have a copy, not a reference
533+
# to an array that might change before draw().
534+
U = ma.masked_invalid(U, copy=True).ravel()
535+
V = ma.masked_invalid(V, copy=True).ravel()
534536
mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
535537
if C is not None:
536-
C = ma.masked_invalid(C, copy=False).ravel()
538+
C = ma.masked_invalid(C, copy=True).ravel()
537539
mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
538540
if mask is ma.nomask:
539541
C = C.filled()

‎lib/matplotlib/tests/test_quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_quiver.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def test_quiver_single():
8282

8383
ax.quiver([1], [1], [2], [2])
8484

85+
@cleanup
86+
def test_quiver_copy():
87+
fig, ax = plt.subplots()
88+
uv = dict(u=np.array([1.1]), v=np.array([2.0]))
89+
q0 = ax.quiver([1], [1], uv['u'], uv['v'])
90+
uv['v'][0] = 0
91+
assert q0.V[0] == 2.0
92+
8593

8694
if __name__ == '__main__':
8795
import nose

0 commit comments

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