How to increase the font size of the FactorPlot/FacetGrid legend

Question:

The instructions from this question don’t work for Seaborn FacetPlots. Would it be possible to get the method to do the same?

Asked By: tangy

||

Answers:

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

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.

Answered By: Hielke Walinga

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.

Answered By: Major Major
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.