我试图使用如下代码在python中绘制一组图形.
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(521)
fig = sm.graphics.tsa.plot_acf(s0, lags=40, ax=ax1)
ax2 = fig.add_subplot(522)
fig = sm.graphics.tsa.plot_pacf(s0, lags=40, ax=ax2)
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(523)
fig = sm.graphics.tsa.plot_acf(s1, lags=40, ax=ax1)
ax2 = fig.add_subplot(524)
fig = sm.graphics.tsa.plot_pacf(s1, lags=40, ax=ax2)
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(525)
fig = sm.graphics.tsa.plot_acf(s2, lags=40, ax=ax1)
ax2 = fig.add_subplot(526)
fig = sm.graphics.tsa.plot_pacf(s2, lags=40, ax=ax2)
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(527)
fig = sm.graphics.tsa.plot_acf(s3, lags=40, ax=ax1)
ax2 = fig.add_subplot(528)
fig = sm.graphics.tsa.plot_pacf(s3, lags=40, ax=ax2)
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(529)
fig = sm.graphics.tsa.plot_acf(s4, lags=40, ax=ax1)
ax2 = fig.add_subplot(5210)
fig = sm.graphics.tsa.plot_pacf(s4, lags=40, ax=ax4)
Run Code Online (Sandbox Code Playgroud)
我绘制了第10个子图的行中有一个错误,第10个子图未显示在输出中.代码如下
ax2 = fig.add_subplot(5210)
fig = sm.graphics.tsa.plot_pacf(s4, lags=40, ax=ax4)
Run Code Online (Sandbox Code Playgroud)
并且错误消息如下
整数子图规范必须是三位数.不是4
我认为问题出在(5210).前两位数字指定图形的行和列,即52表示5列2行,总共10个图表,第3位表示放置编号i> e 1,2 ,3,... 10.事情很好(529),但在(5210)中显示错误.
Ffi*_*ydd 12
5210给出一个错误,因为它天真地期望一个3位整数.问题在于它无法解析您是指"5行,2列,第10个绘图"还是"5行,21列,第0个绘图"等.
您可以通过用逗号分隔数字并将每个数字用作单独的agrument来解决这个问题.那是:
ax2 = fig.add_subplot(5, 2, 10)
Run Code Online (Sandbox Code Playgroud)