【问题标题】:Setting different axis limits for subplots in seaborn在 seaborn 中为子图设置不同的轴限制
【发布时间】:2020-12-23 10:47:07
【问题描述】:

我无法弄清楚为不同的子图设置不同的 Y 轴限制的方法。将最后一条语句 'ax6.set_ylim(0,68)' 作为所有子图的 Y 限制。非常欢迎任何帮助。

fig, (ax1, ax2, ax3,ax4,ax5,ax6) = plt.subplots(nrows=6,ncols=1, sharey=True,figsize=(14,14))


sns.regplot(x=df['Income'], y=df['Murder'], ax=ax1,scatter_kws={'alpha': 0.9, 's': 2.0, 'rasterized': 
False, 'zorder': 1})
ax1.set_ylim(0,10)


sns.regplot(x=df['Income'], y=df['Life Exp'], ax=ax2,scatter_kws={'alpha': 0.9, 's': 2.0, ' 
rasterized': False, 'zorder': 1})
ax2.set_ylim(0,100)


sns.regplot(x=df['Income'], y=df['Illiteracy'], ax=ax3,scatter_kws={'alpha': 0.9, 's': 2.0, 
'rasterized': False, 'zorder': 1})
ax3.set_ylim(0,5)


sns.regplot(x=df['Income'], y=df['Frost'], ax=ax4)
ax4.set_ylim(0,200)

sns.regplot(x=df['Income'], y=df['Population'], ax=ax5)
ax5.set_ylim(0,21198)


sns.regplot(x=df['Income'], y=df['HS Grad'], ax=ax6)
ax6.set_ylim(0,68)

【问题讨论】:

    标签: python plot seaborn visualization scatter


    【解决方案1】:

    您在创建坐标区 (plt.subplots(..., sharey=True, ...)) 时设置了 sharey=True,根据定义,这意味着所有子图都具有相同的范围(ax6 中的那个,因为它是您设置的最后一个)。

    如果您不希望这种行为,只需传递sharey=False

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 1970-01-01
      • 2015-09-19
      • 2015-07-27
      • 1970-01-01
      • 2017-09-24
      • 2014-06-09
      • 2021-12-27
      • 2012-04-22
      相关资源
      最近更新 更多