Reputation: 403
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
Upvotes: 0
Views: 210
Reputation: 374
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.
Upvotes: 1