1212import numpy as np
1313
1414from matplotlib .testing .decorators import image_comparison , cleanup
15- from matplotlib .cbook import MatplotlibDeprecationWarning
1615import matplotlib .pyplot as plt
1716import matplotlib as mpl
18- import matplotlib .patches as mpatches
1917import matplotlib .transforms as mtrans
18+ import matplotlib .collections as mcollections
2019
2120
2221@image_comparison (baseline_images = ['legend_auto1' ], remove_text = True )
@@ -110,7 +109,8 @@ def test_fancy():
110109 plt .subplot (121 )
111110 plt .scatter (list (xrange (10 )), list (xrange (10 , 0 , - 1 )), label = 'XX\n XX' )
112111 plt .plot ([5 ] * 10 , 'o--' , label = 'XX' )
113- plt .errorbar (list (xrange (10 )), list (xrange (10 )), xerr = 0.5 , yerr = 0.5 , label = 'XX' )
112+ plt .errorbar (list (xrange (10 )), list (xrange (10 )), xerr = 0.5 ,
113+ yerr = 0.5 , label = 'XX' )
114114 plt .legend (loc = "center left" , bbox_to_anchor = [1.0 , 0.5 ],
115115 ncol = 2 , shadow = True , title = "My legend" , numpoints = 1 )
116116
@@ -123,7 +123,8 @@ def test_framealpha():
123123 plt .legend (framealpha = 0.5 )
124124
125125
126- @image_comparison (baseline_images = ['scatter_rc3' , 'scatter_rc1' ], remove_text = True )
126+ @image_comparison (baseline_images = ['scatter_rc3' , 'scatter_rc1' ],
127+ remove_text = True )
127128def test_rc ():
128129 # using subplot triggers some offsetbox functionality untested elsewhere
129130 fig = plt .figure ()
@@ -221,8 +222,8 @@ def test_warn_args_kwargs(self):
221222 ax .legend ((lnc , lns ), labels = ('a' , 'b' ))
222223
223224 warn .assert_called_with ("You have mixed positional and keyword "
224- "arguments, some input will be "
225- "discarded." )
225+ "arguments, some input will be "
226+ "discarded." )
226227
227228
228229@image_comparison (baseline_images = ['legend_stackplot' ], extensions = ['png' ])
@@ -273,10 +274,10 @@ def test_nanscatter():
273274
274275@image_comparison (baseline_images = ['not_covering_scatter' ], extensions = ['png' ])
275276def test_not_covering_scatter ():
276- colors = ['b' ,'g' ,'r' ]
277+ colors = ['b' , 'g' , 'r' ]
277278
278279 for n in range (3 ):
279- plt .scatter ([n , ], [n , ], color = colors [n ])
280+ plt .scatter ([n ], [n ], color = colors [n ])
280281
281282 plt .legend (['foo' , 'foo' , 'foo' ], loc = 'best' )
282283 plt .gca ().set_xlim (- 0.5 , 2.2 )
@@ -296,7 +297,28 @@ def test_not_covering_scatter_transform():
296297 plt .legend (['foo' , 'bar' ], loc = 'best' )
297298
298299
300+ @cleanup
301+ def test_linecollection_scaled_dashes ():
302+ lines1 = [[(0 , .5 ), (.5 , 1 )], [(.3 , .6 ), (.2 , .2 )]]
303+ lines2 = [[[0.7 , .2 ], [.8 , .4 ]], [[.5 , .7 ], [.6 , .1 ]]]
304+ lines3 = [[[0.6 , .2 ], [.8 , .4 ]], [[.5 , .7 ], [.1 , .1 ]]]
305+ lc1 = mcollections .LineCollection (lines1 , linestyles = "--" , lw = 3 )
306+ lc2 = mcollections .LineCollection (lines2 , linestyles = "-." )
307+ lc3 = mcollections .LineCollection (lines3 , linestyles = ":" , lw = .5 )
308+
309+ fig , ax = plt .subplots ()
310+ ax .add_collection (lc1 )
311+ ax .add_collection (lc2 )
312+ ax .add_collection (lc3 )
313+
314+ leg = ax .legend ([lc1 , lc2 , lc3 ], ["line1" , "line2" , 'line 3' ])
315+ h1 , h2 , h3 = leg .legendHandles
316+
317+ for oh , lh in zip ((lc1 , lc2 , lc3 ), (h1 , h2 , h3 )):
318+ assert oh .get_linestyles ()[0 ][1 ] == lh ._dashSeq
319+ assert oh .get_linestyles ()[0 ][0 ] == lh ._dashOffset
320+
321+
299322if __name__ == '__main__' :
300323 import nose
301324 nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
302-
0 commit comments