@@ -144,22 +144,6 @@ def test_legend_remove():
144144class TestLegendFunction (object ):
145145 # Tests the legend function on the Axes and pyplot.
146146
147- deprecation_message = ('The "loc" positional argument '
148- 'to legend is deprecated. Please use '
149- 'the "loc" keyword instead.' )
150-
151- @cleanup
152- def test_legend_label_loc_args (self ):
153- # Check the deprecated warning is created and that the appropriate
154- # call to Legend is made. This wouldn't actually create a valid
155- # legend as there is no artist to legendify, but that doesn't matter.
156- with mock .patch ('matplotlib.cbook.warn_deprecated' ) as deprecation :
157- with mock .patch ('matplotlib.legend.Legend' ) as Legend :
158- plt .legend (['hello world' ], 1 )
159-
160- deprecation .assert_called_with ('1.4' , self .deprecation_message )
161- Legend .assert_called_with (plt .gca (), [], ['hello world' ], loc = 1 )
162-
163147 @cleanup
164148 def test_old_legend_handler_interface (self ):
165149 # Check the deprecated warning is created and that the appropriate
@@ -187,18 +171,6 @@ def __call__(self, legend, orig_handle, fontsize, handlebox):
187171 MatplotlibDeprecationWarning ,
188172 stacklevel = 1 )
189173
190- @cleanup
191- def test_legend_handle_label_loc_args (self ):
192- # Check the deprecated warning is created and that the appropriate
193- # call to Legend is made.
194- lines = plt .plot (range (10 ))
195- with mock .patch ('matplotlib.cbook.warn_deprecated' ) as deprecation :
196- with mock .patch ('matplotlib.legend.Legend' ) as Legend :
197- plt .legend (lines , ['hello world' ], 1 )
198-
199- deprecation .assert_called_with ('1.4' , self .deprecation_message )
200- Legend .assert_called_with (plt .gca (), lines , ['hello world' ], loc = 1 )
201-
202174 @cleanup
203175 def test_legend_handle_label (self ):
204176 lines = plt .plot (range (10 ))
@@ -229,6 +201,29 @@ def test_legend_handler_map(self):
229201 plt .legend (handler_map = {'1' : 2 })
230202 handles_labels .assert_called_with ({'1' : 2 })
231203
204+ @cleanup
205+ def test_kwargs (self ):
206+ fig , ax = plt .subplots (1 , 1 )
207+ th = np .linspace (0 , 2 * np .pi , 1024 )
208+ lns , = ax .plot (th , np .sin (th ), label = 'sin' , lw = 5 )
209+ lnc , = ax .plot (th , np .cos (th ), label = 'cos' , lw = 5 )
210+ with mock .patch ('matplotlib.legend.Legend' ) as Legend :
211+ ax .legend (handles = (lnc , lns ), labels = ('a' , 'b' ))
212+ Legend .assert_called_with (ax , (lnc , lns ), ('a' , 'b' ))
213+
214+ @cleanup
215+ def test_warn_args_kwargs (self ):
216+ fig , ax = plt .subplots (1 , 1 )
217+ th = np .linspace (0 , 2 * np .pi , 1024 )
218+ lns , = ax .plot (th , np .sin (th ), label = 'sin' , lw = 5 )
219+ lnc , = ax .plot (th , np .cos (th ), label = 'cos' , lw = 5 )
220+ with mock .patch ('warnings.warn' ) as warn :
221+ ax .legend ((lnc , lns ), labels = ('a' , 'b' ))
222+
223+ warn .assert_called_with ("You have mixed positional and keyword "
224+ "arguments, some input will be "
225+ "be discarded." )
226+
232227
233228@image_comparison (baseline_images = ['legend_stackplot' ], extensions = ['png' ])
234229def test_legend_stackplot ():
0 commit comments