@@ -80,21 +80,21 @@ def test_framealpha():
80
80
plt .legend (framealpha = 0.5 )
81
81
82
82
83
- @image_comparison (baseline_images = ['scatter_rc3' ,'scatter_rc1' ], remove_text = True )
83
+ @image_comparison (baseline_images = ['scatter_rc3' , 'scatter_rc1' ], remove_text = True )
84
84
def test_rc ():
85
85
# using subplot triggers some offsetbox functionality untested elsewhere
86
86
fig = plt .figure ()
87
- ax = plt .subplot (121 )
87
+ ax = plt .subplot (121 )
88
88
ax .scatter (list (xrange (10 )), list (xrange (10 , 0 , - 1 )), label = 'three' )
89
89
ax .legend (loc = "center left" , bbox_to_anchor = [1.0 , 0.5 ],
90
- title = "My legend" )
90
+ title = "My legend" )
91
91
92
92
mpl .rcParams ['legend.scatterpoints' ] = 1
93
93
fig = plt .figure ()
94
- ax = plt .subplot (121 )
94
+ ax = plt .subplot (121 )
95
95
ax .scatter (list (xrange (10 )), list (xrange (10 , 0 , - 1 )), label = 'one' )
96
96
ax .legend (loc = "center left" , bbox_to_anchor = [1.0 , 0.5 ],
97
- title = "My legend" )
97
+ title = "My legend" )
98
98
99
99
100
100
@image_comparison (baseline_images = ['legend_expand' ], remove_text = True )
@@ -113,6 +113,19 @@ def test_legend_expand():
113
113
ax .legend (loc = 3 , mode = mode , ncol = 2 )
114
114
115
115
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
+
116
129
class TestLegendFunction (object ):
117
130
# Tests the legend function on the Axes and pyplot.
118
131
@@ -154,8 +167,8 @@ def __call__(self, legend, orig_handle, fontsize, handlebox):
154
167
handler_map = {None : AnyObjectHandler ()})
155
168
156
169
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.' ,
159
172
MatplotlibDeprecationWarning ,
160
173
stacklevel = 1 )
161
174
0 commit comments