0

I want to plot, show and save multiple plots in matplotplib. So, I used

import matplotlib.pyplot as plt

x1, y1 = [0,1,2,3], [1,2,3,4]
x2, y2 = [0,1,2,3], [1,2,3,4]
x3, y3 = [0,1,2,3], [1,2,3,4]
x4, y4 = [0,1,2,3], [1,2,3,4]
x5, y5 = [0,1,2,3], [1,2,3,4]
x6, y6 = [0,1,2,3], [1,2,3,4]

ax=plt.figure(1)
bx=plt.figure(2)
cx=plt.figure(3)
dx=plt.figure(4)
ex=plt.figure(5)
fx=plt.figure(6)
gx=plt.figure(7)

ax.axes.errorbar(x,y,yerr=std)
bx.axes.errorbar(x1,y1,yerr=std1)
cx.axes.errorbar(x2,y2,yerr=std2)
dx.axes.errorbar(x3,y3,yerr=std3)
ex.axes.errorbar(x4,y4,yerr=std4)
fx.axes.errorbar(x5,y5,yerr=std5)
gx.axes.errorbar(x6,y6,yerr=std6)

ax.figure.show(1)
bx.figure.show(2)
cx.figure.show(3)
dx.figure.show(4)
ex.figure.show(5)
fx.figure.show(6)
gx.figure.show(7)

and I got the error AttributeError: 'list' object has no attribute 'errorbar' and when I use ax.errobar instead of ax.axes.errorbar I get the error AttributeError: 'Figure' object has no attribute 'errorbar' . So, I want to know what is the problem with my code.

Thanks

1 Answer 1

1

Figure.axes is a list of Axes (not an instance of one, because you can have more than one Axes object for each figure). You can get at the axes by indexing into it:

ax.axes[0].errorbar(x,y,yerr=std)

Depending on your set-up, you might also have to add the axes first (e.g. if you get an IndexError). The documentation for Figure has more details.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I read the documentation for Figure but I didn't get how would that work for me with fig.add_axes(ax) .
Did yout try adding the [0] to pull the Axes instance out of the axes list?
Yes I did and I got the index Error, so I referred to the Figure documentation and didn't know how adding axes will help or how to do it

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.