Skip to content

Commit a93cf5a

Browse files
andrzejnovakpre-commit-ci[bot]henryiii
authored
fix: allow overwriting labels for plot/overlay (#414)
* fix: allow overwriting labels for plot/overlay * style: pre-commit fixes * fix: review Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
1 parent 6a6832f commit a93cf5a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/hist/basehist.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,19 @@ 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:
421+
if not isinstance(kwargs["label"], str) and len(kwargs["label"]) == len(
422+
cats
423+
):
424+
cats = kwargs["label"]
425+
kwargs.pop("label")
426+
elif isinstance(kwargs["label"], str):
427+
cats = [kwargs["label"]] * len(cats)
428+
kwargs.pop("label")
429+
else:
430+
raise ValueError(
431+
f"label ``{kwargs['label']}`` not understood for {len(cats)} categories"
432+
)
420433
return plot.histplot(d1hists, ax=ax, label=cats, **_proc_kw_for_lw(kwargs))
421434

422435
def plot2d(

0 commit comments

Comments
 (0)