@@ -80,21 +80,21 @@ def test_framealpha():
8080 plt .legend (framealpha = 0.5 )
8181
8282
83- @image_comparison (baseline_images = ['scatter_rc3' ,'scatter_rc1' ], remove_text = True )
83+ @image_comparison (baseline_images = ['scatter_rc3' , 'scatter_rc1' ], remove_text = True )
8484def test_rc ():
8585 # using subplot triggers some offsetbox functionality untested elsewhere
8686 fig = plt .figure ()
87- ax = plt .subplot (121 )
87+ ax = plt .subplot (121 )
8888 ax .scatter (list (xrange (10 )), list (xrange (10 , 0 , - 1 )), label = 'three' )
8989 ax .legend (loc = "center left" , bbox_to_anchor = [1.0 , 0.5 ],
90- title = "My legend" )
90+ title = "My legend" )
9191
9292 mpl .rcParams ['legend.scatterpoints' ] = 1
9393 fig = plt .figure ()
94- ax = plt .subplot (121 )
94+ ax = plt .subplot (121 )
9595 ax .scatter (list (xrange (10 )), list (xrange (10 , 0 , - 1 )), label = 'one' )
9696 ax .legend (loc = "center left" , bbox_to_anchor = [1.0 , 0.5 ],
97- title = "My legend" )
97+ title = "My legend" )
9898
9999
100100@image_comparison (baseline_images = ['legend_expand' ], remove_text = True )
@@ -113,6 +113,19 @@ def test_legend_expand():
113113 ax .legend (loc = 3 , mode = mode , ncol = 2 )
114114
115115
116+ @cleanup
117+ def test_legend_remove ():
118+ fig = plt .figure ()
119+ ax = fig .add_subplot (1 , 1 , 1 )
120+ lines = ax .plot (range (10 ))
121+ leg = fig .legend (lines , "test" )
122+ leg .remove ()
123+ assert_equal (fig .legends , [])
124+ leg = ax .legend ("test" )
125+ leg .remove ()
126+ assert ax .get_legend () is None
127+
128+
116129class TestLegendFunction (object ):
117130 # Tests the legend function on the Axes and pyplot.
118131
@@ -154,8 +167,8 @@ def __call__(self, legend, orig_handle, fontsize, handlebox):
154167 handler_map = {None : AnyObjectHandler ()})
155168
156169 warn .assert_called_with (u'Legend handers must now implement a '
157- '"legend_artist" method rather than '
158- 'being a callable.' ,
170+ '"legend_artist" method rather than '
171+ 'being a callable.' ,
159172 MatplotlibDeprecationWarning ,
160173 stacklevel = 1 )
161174
0 commit comments