55import sys
66from matplotlib import pyplot as plt
77from 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
1722def 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():
3535def 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+
5264if __name__ == '__main__' :
5365 import nose
5466 nose .runmodule ()
0 commit comments