如何在使用Pandas数据框时为子图设置ylim?

3
我有一个包含三列数据的数据框。 我可以使用ax = plt.gca()设置底部图表,但是如何设置其他子图的限制?
以下是我用于绘图的代码。
SomeDataFrame.plot(subplots=True, style=style, title='%s' % macID.upper(), grid=True, legend=True,)
ax = plt.gca()
ax.ylim=([lowlimit, highlimit])

plt.show()
1个回答

3

SomeDataFrame.plot() 返回创建的子图列表。通过使用该返回值,您可以访问和操作这些子图。

mysubplots = SomeDataFrame.plot(subplots=True, style=style, title='%s' % macID.upper(), grid=True, legend=True,)
firstplot = mysubplots[0]
firstplot.set_ylim=([lowlimit, highlimit])
secondplot = mysubplots[1]
secondplot.set_ylim=([lotherowlimit, otherhighlimit])

plt.show()

1
你测试过这个是否有效吗?因为我认为你需要使用set_ylim()而不是ylim() - Bart
在我的IPython shell和评论字段之间,我丢失了“set_”前缀。谢谢! - Robin Roth
我认为应该使用以下代码:firstplot.set_ylim([lowlimit, highlimit])而不是firstplot.set_ylim=([lowlimit, highlimit])至少对我来说,只有前者才能得到期望的结果,而后者则不能。 - Mihaela Grigore

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接