Unlike most matplotlib legends, one cannot adjust the fontsize of the seaborn.relplot facetgrid's legend.
Per the advice in the accepted answer to How can I change the font size using seaborn FacetGrid?, I tried:
fg = sns.relplot(data=df, kind='line', x='Time', y=signal, hue='role', style='subsignal', dashes=True, linewidth=.5, alpha=.75, ax=None, ci='sd')
plt.setp(fg._legend.get_title(), fontsize=6)
plt.show()
But it didn't change the fontsize in the legend.
It'd be great if one could access and manipulate properties of a matplotlib-legend object from FacetGrid, or if FacetGrid's legend provided deterministically set-able properties like fontsize.
Hi @kusanagee ,
In matplotlib, parameters of visual features may be tweaked by updating the rcParams dictionary, dictating the appearance of many visual parameters. With seaborn you can update the plotting context to have the desired legend fontsize just before creating the relplot, see this example:
import seaborn as sns
import matplotlib.pyplot as plt
df=sns.load_dataset("fmri")
with sns.plotting_context(rc={"legend.fontsize":6}):
g = sns.relplot(data=df, kind='line', x='timepoint', y="signal", hue='event')
plt.show()
I hope this helps.
Thanks @MaozGelbart
Most helpful comment
Hi @kusanagee ,
In matplotlib, parameters of visual features may be tweaked by updating the rcParams dictionary, dictating the appearance of many visual parameters. With seaborn you can update the plotting context to have the desired legend fontsize just before creating the relplot, see this example:
I hope this helps.