如何增加Seaborn图中图例的字体大小? [英] How to increase the font size of the legend in my Seaborn plot?
问题描述
我有以下代码来创建Seaborn带状图.我很难弄清楚如何增加剧情中出现的图例的字体大小.
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="Market", y="Rate", hue="Group",data=myBenchmarkData, jitter=True, size=12, alpha=0.5)
g.axes.set_title("4* Rate Market and by Hotel Groups for Year 2016",fontsize=25)
g.set_xlabel("Market",fontsize=20)
g.set_ylabel("Rate (in EUR)",fontsize=20)
g.tick_params(labelsize=15)
plt.savefig ('benchmark1.png')
我对我的x轴和y轴标签的字体大小没问题,但是我的情节中图例的字体大小很小.如何更改?
I am OK with my x-axis and y-axis labels font size but the font size of the legend in my plot is small. How to change it?
推荐答案
根据此示例使用matplotlib函数setp
:
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()
另一种方法是使用plotting_context
更改所有图形的font_scale
:
http://seaborn.pydata.org/genic/seaborn.plotting_context.html
Another way is to change font_scale
of all graph with plotting_context
:
http://seaborn.pydata.org/generated/seaborn.plotting_context.html
这篇关于如何增加Seaborn图中图例的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!