Skip to content Skip to sidebar Skip to footer

How To Increase The Font Size Of The Legend In My Seaborn Plot?

I have the following codes to create a Seaborn strip plot. I am having a hard time figuring out how to increase the font size of the legend appearing in the plot. g=sns.stripplot(x

Solution 1:

Use matplotlib function setp according to this example:

import seaborn as sns
import matplotlib.pylab as plt
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")

ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
plt.setp(ax.get_legend().get_texts(), fontsize='22') # for legend text
plt.setp(ax.get_legend().get_title(), fontsize='32') # for legend title

plt.show()

enter image description here

Another way is to change font_scale of all graph with plotting_context: http://seaborn.pydata.org/generated/seaborn.plotting_context.html


Solution 2:

There is a much easier way to do this today, simply set up your figure and then call

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.


Post a Comment for "How To Increase The Font Size Of The Legend In My Seaborn Plot?"