Skip to content

Commit 2a3bf41

Browse files
committed
BUG: quiverkey must set the vector figure attribute
1 parent be3da1a commit 2a3bf41

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

lib/matplotlib/quiver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def _init(self):
303303
if self.color is not None:
304304
self.vector.set_color(self.color)
305305
self.vector.set_transform(self.Q.get_transform())
306+
self.vector.set_figure(self.get_figure())
306307
self._initialized = True
307308

308309
def _text_x(self, x):

lib/matplotlib/tests/test_quiver.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
import sys
66
from matplotlib import pyplot as plt
77
from matplotlib.testing.decorators import cleanup
8+
from matplotlib.testing.decorators import image_comparison
89

910

10-
WRITER_OUTPUT = dict(ffmpeg='mp4', ffmpeg_file='mp4',
11-
mencoder='mp4', mencoder_file='mp4',
12-
avconv='mp4', avconv_file='mp4',
13-
imagemagick='gif', imagemagick_file='gif')
11+
def draw_quiver(ax):
12+
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, 1),
13+
np.arange(0, 2 * np.pi, 1))
14+
U = np.cos(X)
15+
V = np.sin(Y)
16+
17+
Q = ax.quiver(U, V)
18+
return Q
1419

1520

1621
@cleanup
1722
def test_quiver_memory_leak():
1823
fig, ax = plt.subplots()
1924

20-
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .04),
21-
np.arange(0, 2 * np.pi, .04))
22-
U = np.cos(X)
23-
V = np.sin(Y)
24-
25-
Q = ax.quiver(U, V)
25+
Q = draw_quiver(ax)
2626
ttX = Q.X
2727
Q.remove()
2828

@@ -35,20 +35,32 @@ def test_quiver_memory_leak():
3535
def test_quiver_key_memory_leak():
3636
fig, ax = plt.subplots()
3737

38-
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .04),
39-
np.arange(0, 2 * np.pi, .04))
40-
U = np.cos(X)
41-
V = np.sin(Y)
42-
43-
Q = ax.quiver(U, V)
38+
Q = draw_quiver(ax)
4439

4540
qk = ax.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$',
46-
labelpos='W',
47-
fontproperties={'weight': 'bold'})
41+
labelpos='W',
42+
fontproperties={'weight': 'bold'})
4843
assert sys.getrefcount(qk) == 3
4944
qk.remove()
5045
assert sys.getrefcount(qk) == 2
5146

47+
48+
@image_comparison(baseline_images=['quiver_with_key_test_image'],
49+
extensions=['png'])
50+
def test_quiver_with_key():
51+
fig, ax = plt.subplots()
52+
ax.margins(0.1)
53+
54+
Q = draw_quiver(ax)
55+
56+
qk = ax.quiverkey(Q, 0.5, 0.95, 2,
57+
r'$2\, \mathrm{m}\, \mathrm{s}^{-1}$',
58+
coordinates='figure',
59+
labelpos='W',
60+
fontproperties={'weight': 'bold',
61+
'size': 'large'})
62+
63+
5264
if __name__ == '__main__':
5365
import nose
5466
nose.runmodule()

0 commit comments

Comments
 (0)