Python 如何在我的Seaborn情节中增加图例的字体大小?
我有以下代码来创建Seaborn strip地块。我很难想出如何增加剧情中出现的图例的字体大小Python 如何在我的Seaborn情节中增加图例的字体大小?,python,matplotlib,legend,seaborn,Python,Matplotlib,Legend,Seaborn,我有以下代码来创建Seaborn strip地块。我很难想出如何增加剧情中出现的图例的字体大小 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("Ma
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函数
setp
:
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()
另一种方法是使用绘图上下文更改所有图形的字体比例
:
现在有一种更简单的方法,只需设置好你的体型,然后打电话
plt.legend(fontsize='x-large', title_fontsize='40')
可能取决于您正在使用的matplotlib的版本。我使用的是2.2.3,它有fontsize
参数,但没有title\u fontsize
如何使用factorplot实现这一点?我得到错误:AttributeError:“FacetGrid”对象没有属性“get_legend”
。但是如何使图例中的标记大小与绘图中的标记大小匹配?@Archie FacetGrid对象在其\u legend
属性中有一个图例。因此,您可以使用setp(g._legend.get_title(),fontsize=32)
对其进行更改。