我需要在一列中从两个 DataFrame 中绘制几列(每个图两列或多列),共享 x 轴。所有数据都有相同的索引。从 [ 1 ]
中获取和修改的示例:
df = DataFrame(randn(1000, 4), index=date_range('1/1/2000', periods=1000), columns=list('AB'))
df2 = DataFrame(randn(1000, 4), index=df.index, columns=list('CD'))
df = df.cumsum()
df2 = df.cumsum()
fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True)
df['A'].plot(ax=axes[0,0])
df2['C'].plot(ax=axes[0,0])
df['B'].plot(ax=axes[1,0])
df2['D'].plot(ax=axes[1,0])
运行这个我得到:IndexError: too many indices
这是一个错误还是我错过了什么?
当我改变ncols=2
时,一切都很好,但有两个额外的空白图。
我可以使用其他解决方案,但上面看起来更好:
ax1 = subplot(211)
df['A'].plot()
df2['C'].plot()
ax2 = subplot(212, sharex=ax1)
df['B'].plot()
df2['D'].plot()