Skip to main content
 首页 » 编程设计

python之如何使用 Pandas 数据框为子图设置 ylim

2025年04月02日12落叶无声

我有不止这些数据框列。 我可以使用 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() 

请您参考如下方法:

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()