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 166e9cc

Browse filesBrowse files
committed
Merge pull request #4250 from efiring/quiver_copy
BUG : Quiver must copy U, V, C args so they can't change before draw()
2 parents 9cf4d3e + 5a88c5e commit 166e9cc
Copy full SHA for 166e9cc

File tree

2 files changed

+14
-3
lines changed
Filter options

2 files changed

+14
-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
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def test_quiver_single():
8383
ax.quiver([1], [1], [2], [2])
8484

8585

86+
@cleanup
87+
def test_quiver_copy():
88+
fig, ax = plt.subplots()
89+
uv = dict(u=np.array([1.1]), v=np.array([2.0]))
90+
q0 = ax.quiver([1], [1], uv['u'], uv['v'])
91+
uv['v'][0] = 0
92+
assert q0.V[0] == 2.0
93+
94+
8695
if __name__ == '__main__':
8796
import nose
8897
nose.runmodule()

0 commit comments

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