Skip to content

Commit 19c9802

Browse files
committed
fix: allow overwriting labels for plot/overlay
1 parent 492ebd6 commit 19c9802

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/hist/basehist.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ def plot1d(
417417
cat_ax = self.axes[overlay]
418418
cats = cat_ax if cat_ax.traits.discrete else np.arange(len(cat_ax.centers))
419419
d1hists = [self[{overlay: cat}] for cat in cats]
420+
if 'label' in kwargs and hasattr(kwargs['label'], 'len'):
421+
if not isinstance(kwargs['label'], str) and len(kwargs['label']) == len(cats):
422+
cats = kwargs['label']
423+
kwargs.pop("label")
424+
elif isinstance(kwargs['label'], str):
425+
cats = [kwargs['label']] * len(cats)
426+
kwargs.pop("label")
427+
else:
428+
raise ValueError(f"label ``{kwargs['label']}`` not understood for {len(cats)} categories")
420429
return plot.histplot(d1hists, ax=ax, label=cats, **_proc_kw_for_lw(kwargs))
421430

422431
def plot2d(

0 commit comments

Comments
 (0)