7

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

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
tangy
  • 3,056
  • 2
  • 25
  • 42
  • [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 Answers3

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