Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot.subplot ---> 'Figure' object has no attribute 'plot'

I am trying to use subplots similar to what is being shown here:

http://matplotlib.org/examples/pylab_examples/subplots_demo.html

axarr = plt.subplots(len(column_list), sharex=True)
subp_num = 0
for j in column_list:
     axarr[subp_num].plot(df.values[2:,j])
     subp_num = subp_num + 1

then I get this error:

axarr[subp_num].plot(df.values[2:,j])
AttributeError: 'Figure' object has no attribute 'plot'

Any hint on what am I doing wrong? Thanks

like image 362
lmblanes Avatar asked May 18 '14 15:05

lmblanes


1 Answers

You have one obvious problem: all of the examples in the link you provide look like

f, axarr = plt.subplots(...)

where the f is the Figure you are subsequently treating as if it had a plot attribute. If you are working with an arbitrary number of subplots, you could do:

axarr = plt.subplots(...)
f, axarr = axarr[0], axarr[1:]

Also, you are using a while loop with an incrementing index, which is clumsy and prone to error; just use a for loop:

for j, ax in zip(column_list, axarr):
    ax.plot(df.values[2:, j])
like image 78
jonrsharpe Avatar answered Nov 19 '22 00:11

jonrsharpe