@@ -513,14 +513,22 @@ def _plot_args(self, axes, tup, kwargs, *,
513513
514514 label = kwargs .get ('label' )
515515 n_datasets = max (ncx , ncy )
516- if n_datasets > 1 and not cbook .is_scalar_or_string (label ):
517- if len (label ) != n_datasets :
518- raise ValueError (f"label must be scalar or have the same "
519- f"length as the input data, but found "
520- f"{ len (label )} for { n_datasets } datasets." )
516+
517+ if cbook .is_scalar_or_string (label ):
518+ labels = [label ] * n_datasets
519+ elif len (label ) == n_datasets :
521520 labels = label
521+ elif n_datasets == 1 :
522+ msg = (f'Passing label as a length { len (label )} sequence when '
523+ 'plotting a single dataset is deprecated in Matplotlib 3.9 '
524+ 'and will error in 3.11. To keep the current behavior, '
525+ 'cast the sequence to string before passing.' )
526+ _api .warn_deprecated ('3.9' , message = msg )
527+ labels = [label ]
522528 else :
523- labels = [label ] * n_datasets
529+ raise ValueError (
530+ f"label must be scalar or have the same length as the input "
531+ f"data, but found { len (label )} for { n_datasets } datasets." )
524532
525533 result = (make_artist (axes , x [:, j % ncx ], y [:, j % ncy ], kw ,
526534 {** kwargs , 'label' : label })
0 commit comments