How to increase the font size of the legend in my Seaborn plot?

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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

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?

回答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() 

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!