From f3a5628995cf37c537e95e3361e01f0f5f521abf Mon Sep 17 00:00:00 2001 From: Maoz Gelbart <13831112+MaozGelbart@users.noreply.github.com> Date: Tue, 27 Oct 2020 00:25:44 +0200 Subject: [PATCH] Fix `adjust_subtitles` when `legend_out=False`. (#2304) * Test adjust_subtitles and legend_out interactions * Fix adjust_subtitles when legend_out is False * Remove redundant smoke tests (cherry picked from commit a9577e705023873de7c7bbf3e9b6ae0dc1880b51) --- seaborn/axisgrid.py | 6 +++--- seaborn/tests/test_axisgrid.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/seaborn/axisgrid.py b/seaborn/axisgrid.py index 1ffdc97082..1b79147d0d 100644 --- a/seaborn/axisgrid.py +++ b/seaborn/axisgrid.py @@ -166,13 +166,13 @@ def add_legend(self, legend_data=None, title=None, label_order=None, ax = self.axes.flat[0] kwargs.setdefault("loc", "best") - if adjust_subtitles: - adjust_legend_subtitles(figlegend) - leg = ax.legend(handles, labels, **kwargs) leg.set_title(title, prop={"size": title_size}) self._legend = leg + if adjust_subtitles: + adjust_legend_subtitles(leg) + return self def _clean_axis(self, ax): diff --git a/seaborn/tests/test_axisgrid.py b/seaborn/tests/test_axisgrid.py index 6f52d9b8d3..46dc9d5196 100644 --- a/seaborn/tests/test_axisgrid.py +++ b/seaborn/tests/test_axisgrid.py @@ -303,6 +303,12 @@ def test_legend_options(self): g1.map(plt.plot, "x", "y") g1.add_legend() + g1 = ag.FacetGrid(self.df, hue="b", legend_out=False) + g1.add_legend(adjust_subtitles=True) + + g1 = ag.FacetGrid(self.df, hue="b", legend_out=False) + g1.add_legend(adjust_subtitles=False) + def test_legendout_with_colwrap(self): g = ag.FacetGrid(self.df, col="d", hue='b',