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

Skip to content

Commit bae1eff

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

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-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: 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)