@@ -1347,16 +1347,13 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
13471347 The legend handles.
13481348 labels : list of str
13491349 The legend labels.
1350- extra_args : tuple
1351- *args* with positional handles and labels removed.
13521350 kwargs : dict
13531351 *kwargs* with keywords handles and labels removed.
13541352
13551353 """
13561354 log = logging .getLogger (__name__ )
13571355
13581356 handlers = kwargs .get ('handler_map' )
1359- extra_args = ()
13601357
13611358 if (handles is not None or labels is not None ) and args :
13621359 _api .warn_external ("You have mixed positional and keyword arguments, "
@@ -1374,17 +1371,15 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
13741371 handles = [handle for handle , label
13751372 in zip (_get_legend_handles (axs , handlers ), labels )]
13761373
1377- # No arguments - automatically detect labels and handles.
1378- elif len (args ) == 0 :
1374+ elif len (args ) == 0 : # 0 args: automatically detect labels and handles.
13791375 handles , labels = _get_legend_handles_labels (axs , handlers )
13801376 if not handles :
13811377 log .warning (
13821378 "No artists with labels found to put in legend. Note that "
13831379 "artists whose label start with an underscore are ignored "
13841380 "when legend() is called with no argument." )
13851381
1386- # One argument. User defined labels - automatic handle detection.
1387- elif len (args ) == 1 :
1382+ elif len (args ) == 1 : # 1 arg: user defined labels, automatic handle detection.
13881383 labels , = args
13891384 if any (isinstance (l , Artist ) for l in labels ):
13901385 raise TypeError ("A single argument passed to legend() must be a "
@@ -1394,10 +1389,10 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
13941389 handles = [handle for handle , label
13951390 in zip (_get_legend_handles (axs , handlers ), labels )]
13961391
1397- # Two arguments:
1398- # * user defined handles and labels
1399- else :
1392+ elif len (args ) == 2 : # 2 args: user defined handles and labels.
14001393 handles , labels = args [:2 ]
1401- extra_args = args [2 :]
14021394
1403- return handles , labels , extra_args , kwargs
1395+ else :
1396+ raise _api .nargs_error ('legend' , '0-2' , len (args ))
1397+
1398+ return handles , labels , kwargs
0 commit comments