2015-09-17 70 views
0

我想在matplotplib中繪製,顯示並保存多個圖。所以,我用當在多個窗口中繪製多個圖時,Matplotlib AttributeError

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) 

,我得到了錯誤AttributeError: 'list' object has no attribute 'errorbar',當我使用ax.errobar,而不是ax.axes.errorbar我得到的錯誤AttributeError: 'Figure' object has no attribute 'errorbar' 。所以,我想知道我的代碼有什麼問題。

感謝

回答

1

Figure.axesAxes列表(沒有之一的實例,因爲你可以爲每個人物不止一個Axes對象)。您可以根據索引的軸得到:

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

根據您的設置,您可能還需要先加入的軸(例如,如果你得到一個IndexError)。 該documentation for Figure有更多的細節。

+0

謝謝。我閱讀了「圖」的文檔,但我沒有得到如何用'fig.add_axes(ax)'工作。 – motaha

+0

您是否嘗試添加'[0]'將'Axes'實例拉出'axes'列表? –

+0

是的,我做了,我得到了索引錯誤,所以我參考了'圖'文檔,並不知道如何添加軸將有助於或如何做到這一點 – motaha

相關問題