Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am trying to plot a 5*2 plot in python

I am trying to plot a set of graphs in python using the code as below.

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)

There is a error in the line where i have plotted 10th subplot and the 10th subplot is not getting displayed in output. The code is as follows

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

and the error message is as follows

Integer subplot specification must be a three digit number. Not 4

I think the problem is with (5210).The first two digit specify the rows and columns of graphs i.e 52 means 5 columns and 2 rows, a total of 10 graphs and the 3rd digit refers to the placement number i>e 1,2,3,...10. things work fine upto (529) but shows a error in (5210).

like image 286
VINAY S G Avatar asked Jun 01 '15 10:06

VINAY S G


People also ask

How do you plot 4 subplots in Python?

To create multiple plots use matplotlib. pyplot. subplots method which returns the figure along with Axes object or array of Axes object. nrows, ncols attributes of subplots() method determine the number of rows and columns of the subplot grid.


1 Answers

5210 gives an error because it naively expects a 3-digit integer. The issue is that it cannot parse whether you mean "5 rows, 2 columns, 10th plot" or "5 rows, 21 columns, 0th plot", etc.

You can get around this by separating the numbers with commas and using each as a separate agrument. That is:

ax2 = fig.add_subplot(5, 2, 10)
like image 153
Ffisegydd Avatar answered Sep 30 '22 00:09

Ffisegydd