5
5
import sys
6
6
from matplotlib import pyplot as plt
7
7
from matplotlib .testing .decorators import cleanup
8
+ from matplotlib .testing .decorators import image_comparison
8
9
9
10
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
14
19
15
20
16
21
@cleanup
17
22
def test_quiver_memory_leak ():
18
23
fig , ax = plt .subplots ()
19
24
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 )
26
26
ttX = Q .X
27
27
Q .remove ()
28
28
@@ -35,20 +35,32 @@ def test_quiver_memory_leak():
35
35
def test_quiver_key_memory_leak ():
36
36
fig , ax = plt .subplots ()
37
37
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 )
44
39
45
40
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' })
48
43
assert sys .getrefcount (qk ) == 3
49
44
qk .remove ()
50
45
assert sys .getrefcount (qk ) == 2
51
46
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
+
52
64
if __name__ == '__main__' :
53
65
import nose
54
66
nose .runmodule ()
0 commit comments