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

如何调整Python箱线图(Boxplot)Y轴标签的字体大小

Fixing Y-axis Label Font Size in Seaborn Boxplot

Hey there! I notice your Y-axis label is too small to read clearly in your boxplot—let's get this sorted out right away.

Looking at your code, you've correctly set the font size for the X-axis label with plt.xlabel(), but you haven't applied the same setting to the Y-axis label. That's exactly why it's hard to read!

Quick Fix: Add Y-axis Label Font Size

Just add a plt.ylabel() line with the fontsize parameter, matching what you used for the X-axis (or adjust to a size that works better for you):

import seaborn as sns
import matplotlib.pyplot as plt

# Your original boxplot code
sns.boxplot(x='purpose', y='fico', data=loans, linewidth=2.5, width=0.5)
plt.xlabel('purpose', fontsize=12)
# Add this line to set Y-axis label font size
plt.ylabel('fico', fontsize=12)
plt.yscale('linear')

# Optional: If Y-axis tick numbers are also too small, adjust them too
plt.tick_params(axis='y', labelsize=10)

plt.show()

Extra Tips for Better Readability

  • Adjust Tick Labels: Use plt.tick_params(axis='y', labelsize=...) to make the Y-axis tick numbers larger, just like I did in the example above. Swap axis='y' for axis='x' if you need to tweak the X-axis ticks too.
  • Global Settings (for all plots): If you want all your plots to have consistent label sizes, set these global parameters at the start of your script:
    plt.rcParams['axes.labelsize'] = 12  # For all axis labels
    plt.rcParams['ytick.labelsize'] = 10  # For Y-axis ticks
    plt.rcParams['xtick.labelsize'] = 10  # For X-axis ticks
    
    Then you can omit the fontsize parameter in individual plt.xlabel()/plt.ylabel() calls.

That should make your Y-axis label and ticks nice and clear!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:38:22