我试图在python中绘制一个5 * 2的情节

时间:2015-06-01 10:04:33

标签: python matplotlib

我正在尝试使用下面的代码在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)

我绘制了第10个子图的行中出现错误,第10个子图未显示在输出中。 代码如下

ax2 = fig.add_subplot(5210)
fig = sm.graphics.tsa.plot_pacf(s4, lags=40, ax=ax4)

,错误信息如下

整数子图规范必须是三位数。不是4

我认为问题在于(5210)。前两位用于指定图形的行和列,即52表示5列2行,总共10个图形,第3位表示放置编号i> e 1,2,3,... 10。事情很好(529),但在(5210)中显示错误。

1 个答案:

答案 0 :(得分:10)

5210给出错误,因为它天真地期望一个3位整数。问题在于它无法解析您是否意味着“5行,2列,第10个绘图”“5行,21列,第0个绘图”等。

你可以通过用逗号分隔数字并将每个数字作为单独的agrument来解决这个问题。那就是:

ax2 = fig.add_subplot(5, 2, 10)