我遇到以下问题:
import numpy as np
import pandas as pd
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
xx = np.arange(10)
yy = np.arange(10)
zz = pd.Series(np.arange(10))
fig = plt.figure()
gs = gridspec.GridSpec(1,6)
ax0 = plt.subplot(gs[0,0:2])
zz.plot(ax=ax0)
ax1 = plt.subplot(gs[0,2:4])
zz.plot(ax=ax1)
ax2 = plt.subplot(gs[0,4:])
#plt.plot(xx,yy)
zz.plot(ax=ax2)
plt.savefig('test.png')
plt.close()
我收到错误:
IndexError: index 4 is out of bounds for axis 1 with size 4
但是,当我替换
时zz.plot(ax=ax2)
与
plt.plot(xx,yy)
它工作正常。任何人都可以帮助我理解为什么Pandas会产生这个错误吗?