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',