如何将 Pandas 自相关图添加为子图?

问题描述

我有 4 个子图...

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

ax1.plot(df.index,df['a'],linewidth=0.5,color='w')
ax2.plot(df.index,df['b'],color='w')
ax3.plot(df.index,df['c'],linewidth=0.75,color='r')
ax4.plot(df.index,df['d'],color='g')

想要第 5 个,这恰好是 Pandas 自相关...

x = pd.plotting.autocorrelation_plot(df['a'])
ax5.subplot(x)

不幸的是,这只是显示了最后一个情节消除了其他前 4 个。

你有任何关于如何显示所有 5 个图的线索吗?

解决方法

正如所评论的,autocorrelation_plot(以及一般的熊猫绘图函数)接受一个 ax 参数:

pd.plotting.autocorrelation_plot(df['a'],ax=ax5)