You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Seaborn绘图中标题与坐标轴标签位于边界的调整方法

解决Seaborn displot标题与坐标轴标签贴边界的问题

因为sns.displot()返回的是FacetGrid对象(而非单个Axes),默认布局可能会让标题、标签贴近图边界,可通过以下几种方式调整:

方法1:自动调整布局(最简单)

调用tight_layout()方法让系统自动优化元素位置,避免重叠或贴边:

ax2 = sns.displot(outlist)
ax2.set(xlabel='Rate(Hz)', title='Distribution of publication rates')
ax2.tight_layout()

方法2:手动调整子图边距

通过subplots_adjust()自定义顶部、底部的边距空间,给标题和标签留出足够位置:

ax2 = sns.displot(outlist)
ax2.set(xlabel='Rate(Hz)', title='Distribution of publication rates')
# top控制标题上方空间,bottom控制x轴标签下方空间,可按需调整数值
ax2.subplots_adjust(top=0.9, bottom=0.15)

方法3:单独调整标题与标签位置

如果需要更精细的控制,可以获取FacetGrid内部的Axes对象,分别调整标题偏移和标签间距:

ax2 = sns.displot(outlist)
ax2.set(xlabel='Rate(Hz)', title='Distribution of publication rates')
# 获取子图的Axes实例
ax = ax2.axes[0, 0]
# 调整x轴标签与坐标轴的距离(单位:像素)
ax.xaxis.labelpad = 10
# 调整标题的垂直位置,y值大于1时会向上偏移
ax.title.set_y(1.05)

内容的提问来源于stack exchange,提问作者KansaiRobot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 11:42:06