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

Skip to content

Commit 5852d83

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()
1 parent 489de41 commit 5852d83

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
@@ -514,11 +514,13 @@ def draw(self, renderer):
514514
mcollections.PolyCollection.draw(self, renderer)
515515

516516
def set_UVC(self, U, V, C=None):
517-
U = ma.masked_invalid(U, copy=False).ravel()
518-
V = ma.masked_invalid(V, copy=False).ravel()
517+
# We need to ensure we have a copy, not a reference
518+
# to an array that might change before draw().
519+
U = ma.masked_invalid(U, copy=True).ravel()
520+
V = ma.masked_invalid(V, copy=True).ravel()
519521
mask = ma.mask_or(U.mask, V.mask, copy=False, shrink=True)
520522
if C is not None:
521-
C = ma.masked_invalid(C, copy=False).ravel()
523+
C = ma.masked_invalid(C, copy=True).ravel()
522524
mask = ma.mask_or(mask, C.mask, copy=False, shrink=True)
523525
if mask is ma.nomask:
524526
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)