How to increase the font size of the legend in my Seaborn plot?
我有以下代码来创建Seaborn带状图。 我很难弄清楚如何增加剧情中出现的图例的字体大小。
1 2 3 4 5 6 | 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轴标签的字体大小,但是绘图中图例的字体大小很小。 怎么改变呢?
根据此示例,使用matplotlib函数
1 2 3 4 5 6 7 8 9 10 | 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() |
另一种方法是使用
http://seaborn.pydata.org/generation/seaborn.plotting_context.html
今天有一种更简单的方法,只需设置好身材然后打电话
1 | plt.legend(fontsize='x-large', title_fontsize='40') |
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html
可能取决于您使用的matplotlib的版本。 我正在使用2.2.3,它具有