The instructions from this question don't work for Seaborn FacetPlots. Would it be possible to get the method to do the same?
Asked
Active
Viewed 9,677 times
7
-
[Duplicate](https://stackoverflow.com/questions/25328003/how-can-i-change-the-font-size-using-seaborn-facetgrid) – W Stokvis May 06 '18 at 16:26
-
I only want to modify the legend font size(title/text separately) - just like in the question linked above. – tangy May 06 '18 at 16:32
3 Answers
11
A facetgrid legend is not part of the axes, but part of the facetgrid object. The legend is still a standard matplotlib legend and can be manipulated as such.
plt.setp(g._legend.get_title(), fontsize=20)
Where g is your facetgrid object returned after you call the function making it.

Hielke Walinga
- 2,677
- 1
- 17
- 30
-
`plt.setp(e._legend.get_texts(), fontsize=40)` work for increase legend text – upuil Jul 03 '22 at 10:14
2
If you're using a newer version of matplotlib there's an easier way to change legend font sizes -
plt.legend(fontsize='x-large', title_fontsize='40')
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html
Might depend on the version of matplotlib you're using. I'm using 2.2.3 and it has the fontsize
parameter but not the title_fontsize
.

Major Major
- 2,697
- 3
- 27
- 35
0
As in the linked answer you may use setp
to set the properties (in this case the fontsize of the legend).
The only difference to the linked question is that you need to do that for each axes of the FacetGrid
g = FacetGrid( ... )
for ax in g.axes.flat:
plt.setp(ax.get_legend().get_texts(), fontsize=22) # for legend text
plt.setp(ax.get_legend().get_title(), fontsize=32) # for legend title

ImportanceOfBeingErnest
- 321,279
- 53
- 665
- 712
-
1This gives the following error: `AttributeError: 'FacetGrid' object has no attribute 'get_legend'`. Its also mentioned in the comment on that linked answer. – tangy May 06 '18 at 19:35
-
You cannot get this error from the code I propose here. – ImportanceOfBeingErnest May 06 '18 at 19:36
-
-
Also to add to this answer, if using a `sns.factorplot`, you need to do `ax[0].get_legend()....` – tangy May 06 '18 at 22:29
-
This may be deprecated, no longer works. The solution from @Hielke Walinga is currently accurate. – John Conor Dec 02 '21 at 20:32
-