Q: plotting a row of 3 plots using matplotlib and numpy but getting "IndexError: too many indices for array" I am trying to plot a panel of 3 plots using matplotlib and the subplots() method. I have a numpy array of the mean values for the data and a second array for the standard error for the mean values. I tried to create a plot but keep getting an IndexError: too many indices for array.
The numpy array looks like this:
mean_matrix
f1    f2    f3
8.3   4.1   12.9
8.5   4.3   11.2

std_matrix
f1    f2    f3
2.3   0.4   1.2
1.2   0.2  1.3

So here is my code. As you can see, I am trying to plot the mean and then use a fill for 1.96 times the standard error.
f, axarr = plt.subplots(nrows = 1, ncols=3)

axarr[0,0].plot(range(duration), mean_matrix['f1'], subplots=True)
axarr[0,0].fill_between(range(duration), mean_matrix['f1'] +
                    1.96*std_matrix['f1'], mean_matrix['f1'] -
                    1.96*std_matrix['f1'], alpha=0.5)

axarr[0,1].plot(range(duration), mean_matrix['f2'], subplots=True)
axarr[0,1].fill_between(range(duration), mean_matrix['f2'] +
                    1.96*std_matrix['f2'], mean_matrix['f2'] -
                    1.96*std_matrix['f2'], alpha=0.5 )

axarr[0,2].plot(range(duration), mean_matrix['f3'], subplots=True)
axarr[0,2].fill_between(range(duration), mean_matrix['f3'] +
                    1.96*std_matrix['f3'], mean_matrix['f3'] -
                    1.96*std_matrix['f3'], alpha=0.5 )

I get the error: IndexError: too many indices for array

A: If you issue the subplots command:
f, axarr = plt.subplots(nrows = 1, ncols=3)

You will find that
In [7]: axarr.shape
Out[7]: (3,)

In other words, it is a 1d array. Trying to access it with two indices should give an error:
In [4]: axarr
Out[4]: 
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f0e299dead0>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f0e107d3110>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f0e1804d5d0>], dtype=object)

In [5]: axarr[0,0]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-5-3e75475f2c86> in <module>()
----> 1 axarr[0,0]

IndexError: too many indices

Just try your plot commands with axarr[0] etc.

As @all_m noted, this behaviour is expected if either nrows==1 or ncols==1 in the subplots call, i.e. if you either have a single row or a single column of subplots.
