Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 166e9cc

Browse 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

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/matplotlib/quiver.py

Lines 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

Lines 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)