From cc3869f2ba75b81a9ad1ae7e14780d6ff37ec2a5 Mon Sep 17 00:00:00 2001 From: Maoz Gelbart <13831112+MaozGelbart@users.noreply.github.com> Date: Mon, 1 Aug 2022 17:55:33 +0300 Subject: [PATCH 1/5] Simplify jitter stripplot example --- examples/jitter_stripplot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/jitter_stripplot.py b/examples/jitter_stripplot.py index e5abf78ce3..a0f6ae6c1d 100644 --- a/examples/jitter_stripplot.py +++ b/examples/jitter_stripplot.py @@ -19,7 +19,8 @@ # Show each observation with a scatterplot sns.stripplot(x="value", y="measurement", hue="species", - data=iris, dodge=True, alpha=.25, zorder=1) + data=iris, dodge=True, alpha=.25, zorder=1, + legend=False) # Show the conditional means, aligning each pointplot in the # center of the strips by adjusting the width allotted to each @@ -30,7 +31,6 @@ markers="d", scale=.75, ci=None) # Improve the legend -handles, labels = ax.get_legend_handles_labels() -ax.legend(handles[3:], labels[3:], title="species", - handletextpad=0, columnspacing=1, - loc="lower right", ncol=3, frameon=True) +sns.move_legend( + ax, loc="lower right", ncol=3, frameon=True, columnspacing=1, handletextpad=0 +) From 493077a45962c35efdda619a581cc9554f7d8cee Mon Sep 17 00:00:00 2001 From: Maoz Gelbart <13831112+MaozGelbart@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:57:34 +0300 Subject: [PATCH 2/5] Document the legend argument --- seaborn/categorical.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index fe2c6fd1e2..d7e8d12b3a 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -2133,6 +2133,10 @@ def plot(self, ax, boxplot_kws): Function for converting categorical data into strings. Affects both grouping and tick labels.\ """), + legend=dedent("""\ + legend : str or bool, optional + If `False` or an empty string and `hue` is used, don't draw a legend. + """), ax_in=dedent("""\ ax : matplotlib Axes, optional Axes object to draw the plot onto, otherwise uses the current Axes.\ @@ -2542,6 +2546,7 @@ def stripplot( {linewidth} {native_scale} {formatter} + {legend} {ax_in} kwargs : key, value mappings Other keyword arguments are passed through to @@ -2663,6 +2668,7 @@ def swarmplot( {linewidth} {native_scale} {formatter} + {legend} {ax_in} kwargs : key, value mappings Other keyword arguments are passed through to @@ -3272,7 +3278,7 @@ def catplot( {color} {palette} {hue_norm} - legend : bool, optional + legend : str or bool, optional If ``True`` and there is a ``hue`` variable, draw a legend on the plot. {legend_out} {share_xy} From fbe415174468763abfb09c73254efef23eb8d3b8 Mon Sep 17 00:00:00 2001 From: Maoz Gelbart <13831112+MaozGelbart@users.noreply.github.com> Date: Mon, 1 Aug 2022 22:25:47 +0300 Subject: [PATCH 3/5] Demonstrate 0.11 legend behavior in docstrings --- doc/_docstrings/stripplot.ipynb | 2 +- doc/_docstrings/swarmplot.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/_docstrings/stripplot.ipynb b/doc/_docstrings/stripplot.ipynb index 0dbe3f14d2..34264355a7 100644 --- a/doc/_docstrings/stripplot.ipynb +++ b/doc/_docstrings/stripplot.ipynb @@ -76,7 +76,7 @@ "metadata": {}, "outputs": [], "source": [ - "sns.stripplot(data=tips, x=\"total_bill\", y=\"day\", hue=\"day\")" + "sns.stripplot(data=tips, x=\"total_bill\", y=\"day\", hue=\"day\", legend=False)" ] }, { diff --git a/doc/_docstrings/swarmplot.ipynb b/doc/_docstrings/swarmplot.ipynb index e5f6d9e916..3ad69287f3 100644 --- a/doc/_docstrings/swarmplot.ipynb +++ b/doc/_docstrings/swarmplot.ipynb @@ -76,7 +76,7 @@ "metadata": {}, "outputs": [], "source": [ - "sns.swarmplot(data=tips, x=\"total_bill\", y=\"day\", hue=\"day\")" + "sns.swarmplot(data=tips, x=\"total_bill\", y=\"day\", hue=\"day\", legend=False)" ] }, { From c7a5adbe717d8cd913ea4e009a72a2d8d773abf2 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Tue, 2 Aug 2022 20:53:34 -0400 Subject: [PATCH 4/5] Include more info on legend for numeric variables --- seaborn/categorical.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index d7e8d12b3a..8e54c5197f 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -2134,8 +2134,12 @@ def plot(self, ax, boxplot_kws): and tick labels.\ """), legend=dedent("""\ - legend : str or bool, optional - If `False` or an empty string and `hue` is used, don't draw a legend. +legend : "auto", "brief", "full", or False + How to draw the legend. If "brief", numeric `hue` and `size` + variables will be represented with a sample of evenly spaced values. + If "full", every group will get an entry in the legend. If "auto", + choose between brief or full representation based on number of levels. + If `False`, no legend data is added and no legend is drawn. """), ax_in=dedent("""\ ax : matplotlib Axes, optional From dac54fa15376cc1a78b058405e184b8588a43d2e Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Tue, 2 Aug 2022 20:53:50 -0400 Subject: [PATCH 5/5] Include more info on legend for numeric variables --- seaborn/categorical.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seaborn/categorical.py b/seaborn/categorical.py index 8e54c5197f..0305a08b1e 100644 --- a/seaborn/categorical.py +++ b/seaborn/categorical.py @@ -3283,7 +3283,8 @@ def catplot( {palette} {hue_norm} legend : str or bool, optional - If ``True`` and there is a ``hue`` variable, draw a legend on the plot. + Set to `False` to disable the legend. With `strip` or `swarm` plots, + this also accepts a string, as described in the axes-level docstrings. {legend_out} {share_xy} {margin_titles}