[英]How to change the font size in axis in Seaborn
I don't know why I tried so many times and still failed in changing the font size on either the x-axis or the y-axis in the plot.我不知道为什么我尝试了这么多次,但仍然无法更改 plot 中 x 轴或 y 轴上的字体大小。
Also, there is a small title in the legend showing Gender Code(which is super small).此外,图例中有一个小标题显示性别代码(超小)。
I tried我试过了
sns.set(font_scale=4)
Or或者
plt.rcParams["axes.labelsize"] = 20
But it doesn't make any sense.但这没有任何意义。 Is that because I used them in the wrong position?
那是因为我在错误的 position 中使用了它们吗?
As for the font size on the x-and-axes of your plot, and if you're plotting your seaborn graph on a matplotlib axis (which you should be doing), you can do (with axes
being the name of the axis):至于 plot 的 x 轴和轴上的字体大小,如果您在 matplotlib 轴上绘制 seaborn 图形,您可以使用轴(您应该使用
axes
的名称) :
for tick in axes.xaxis.get_major_ticks():
tick.label.set_fontsize(10)
for tick in axes.yaxis.get_major_ticks():
tick.label.set_fontsize(10)
For the font of the legend, you can try:对于图例的字体,您可以尝试:
axes.legend(prop=dict(size=10))
Please tell if this does not solve your problem!请告诉这是否不能解决您的问题!
EDIT编辑
With what you're giving as code, I guess you could do:使用您提供的代码,我想您可以这样做:
fig, axes = plt.subplots(figsize=(12, 9))
sns.boxplot(x="Benefits", y="Years In Job", hue="Gender Code", data = wk[(wk.Status=="A")], palette="Set3", ax=axes)
plt.title("Boxplot for Years In Job of Active Employees Under Different Benefit Types ", size=20, loc='right')
plt.xlabel("Benefit Type")
for tick in axes.xaxis.get_major_ticks():
tick.label.set_fontsize(10)
for tick in axes.yaxis.get_major_ticks():
tick.label.set_fontsize(10)
axes.legend(prop=dict(size=10))
Add the below line to your code and it should increase the legend size将以下行添加到您的代码中,它应该增加图例大小
ax.legend(loc='upper left', fontsize=30)
Hope that helps希望有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.