首页 > 解决方案 > 在 Seaborn catplot 中更改轴标签大小

问题描述

我正在尝试放大 x 轴标签(即“陆上”、“海上”和“太阳能”),同时旋转它们。但是每当我增加大小时,我的 cat 子图的列大小就会减小并压缩图像。有没有办法在不减少/压缩 seaborn catplot 中的子图的情况下增加轴标签的字体大小?

这是我的代码:

#plt.subplots(figsize=(28,12))
sns.set_theme(style = "whitegrid", font_scale= 1.9)
ax = sns.catplot(x="generator", y="ELCC", hue="Nameplate Capacity",
            col="Scenario", aspect=.7,
            kind="box",palette = 'RdYlBu', data=final_df)
plt.legend(bbox_to_anchor = (1, 1))
ax.set_xticklabels(rotation = 30)
ax.set_xlabels('Generator Type', fontsize=20) # not set_label
ax.set_ylabels('ELCC', fontsize= 20)
ax.fig.set_size_inches(45,22)
plt.show()

到目前为止我的情节:

标签: matplotlibseabornaxis-labelsfacet-gridcatplot

解决方案


对于那些面临同样问题的人 - 我找到了一个解决方法,可以在 Seaborn 中使用 catplot 的“高度”和“纵横比”参数。每个面或每个子图的宽度等于高度*纵横比。这个stackoverflow 帖子很有帮助。


推荐阅读