Skip to content

Commit 18a3bee

Browse files
committed
Add multiple labels support to Axes.plot()
1 parent 8808573 commit 18a3bee

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import OrderedDict
2+
from collections.abc import Iterable
23
from contextlib import ExitStack
34
import functools
45
import inspect
@@ -446,8 +447,22 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
446447
ncx, ncy = x.shape[1], y.shape[1]
447448
if ncx > 1 and ncy > 1 and ncx != ncy:
448449
raise ValueError(f"x has {ncx} columns but y has {ncy} columns")
450+
451+
if ('label' in kwargs and isinstance(kwargs['label'], Iterable)
452+
and not isinstance(kwargs['label'], str)):
453+
if len(kwargs['label']) != max(ncx, ncy):
454+
raise ValueError(f"if label is iterable label and input data"
455+
f" must have same length, but have lengths "
456+
f"{len(kwargs['label'])} and "
457+
f"{max(ncx, ncy)}")
458+
459+
result = (func(x[:, j % ncx], y[:, j % ncy], kw,
460+
{**kwargs, 'label':kwargs['label'][j]})
461+
for j in range(max(ncx, ncy)))
462+
449463
result = (func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
450-
for j in range(max(ncx, ncy)))
464+
for j in range(max(ncx, ncy)))
465+
451466
if return_kwargs:
452467
return list(result)
453468
else:

0 commit comments

Comments
 (0)