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

13,562

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])
Share:
13,562
lmblanes
Author by

lmblanes

Updated on June 09, 2022

Comments

  • lmblanes
    lmblanes almost 2 years

    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