6

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

1 Answer 1

9

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.