【问题标题】:I am trying to plot a 5*2 plot in python我正在尝试在 python 中绘制一个 5*2 的图
【发布时间】:2015-06-01 18:30:04
【问题描述】:

我正在尝试使用以下代码在 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 个图形,第三位是指放置编号 i>e 1,2,3,...10。在 (529) 之前一切正常,但在 (5210) 中显示错误。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    5210 给出一个错误,因为它天真地期望一个 3 位整数。问题是它无法解析您的意思是 "5 rows, 2 columns, 10th plot" 还是 "5 rows, 21 columns, 0th plot" 等等。 p>

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

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

    【讨论】:

    • @VINAYSG 太好了。如果你觉得我的回答对你有帮助,可以accept my answer
    猜你喜欢
    • 2022-12-18
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多