Setting Yaxis in Matplotlib using Pandas

家住魔仙堡 提交于 2019-12-03 04:40:57

Pandas plot() returns the axes, you can use it to set the ylim on it.

ax1 = df2250.plot()
ax2 = df2260.plot()
ax3 = df5.plot()

ax1.set_ylim(100000,500000)
ax2.set_ylim(100000,500000)
etc...

You can also pass an axes to Pandas plot, so plotting it in the same axes can be done like:

ax1 = df2250.plot()
df2260.plot(ax=ax1)
etc...

If you want a lot of different plots, defining the axes on forehand and within one figure might be a solution that gives you most control:

fig, axs = plt.subplots(1,3,figsize=(10,4), subplot_kw={'ylim': (100000,500000)})

df2260.plot(ax=axs[0])
df2260.plot(ax=axs[1])
etc...

I'm guessing this was a feature added after this answer was accepted in 2013; DataFrame.plot() now exposes a ylim parameter that sets the y axis limits:

df.plot(ylim=(0,200))

See pandas documentation for details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!