微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为seaborn中的子图设置不同的轴限制

如何解决为seaborn中的子图设置不同的轴限制

我不知道如何为不同的子图设置不同的 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,' 
rasterized': False,'zorder': 1})
ax2.set_ylim(0,100)


sns.regplot(x=df['Income'],y=df['Illiteracy'],ax=ax3,'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)

解决方法

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。