From 021a20f06f41212fd8c55680a8cc3bf0924e1b30 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Fri, 28 Oct 2022 19:23:01 -0400 Subject: [PATCH] Don't pass label when creating color cycle scout (#3116) * Don't pass label when creating color cycle scout * Update release notes --- doc/whatsnew/v0.12.2.rst | 4 +++- seaborn/utils.py | 3 +++ tests/test_distributions.py | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/whatsnew/v0.12.2.rst b/doc/whatsnew/v0.12.2.rst index dc29ab7402..6bf7ee0814 100644 --- a/doc/whatsnew/v0.12.2.rst +++ b/doc/whatsnew/v0.12.2.rst @@ -2,4 +2,6 @@ v0.12.2 (Unreleased) -------------------- -- Added the :class:`objects.KDE` stat (:pr:`3111`). +- |Feature| Added the :class:`objects.KDE` stat (:pr:`3111`). + +- |Fix| Fixed a regression in v0.12.0 where manually-added labels could have duplicate legend entries (:pr:`3116`). diff --git a/seaborn/utils.py b/seaborn/utils.py index a4887b2c42..f1628130d8 100644 --- a/seaborn/utils.py +++ b/seaborn/utils.py @@ -95,6 +95,9 @@ def _default_color(method, hue, color, kws): # warnings.warn(msg) return None + kws = kws.copy() + kws.pop("label", None) + if color is not None: return color diff --git a/tests/test_distributions.py b/tests/test_distributions.py index c4d62fa340..f881969b67 100644 --- a/tests/test_distributions.py +++ b/tests/test_distributions.py @@ -1816,6 +1816,13 @@ def test_step_line_kwargs(self, flat_series): assert line.get_linewidth() == lw assert line.get_linestyle() == ls + def test_label(self, flat_series): + + ax = histplot(flat_series, label="a label") + handles, labels = ax.get_legend_handles_labels() + assert len(handles) == 1 + assert labels == ["a label"] + class TestHistPlotBivariate: