2013-09-25 89 views
2

我試圖在一個圖中繪製大量的盒形圖。我成功展示了9個箱子,我想獲得更多的箱子。我使用了下面的代碼。 從csv文件獲取數據:boxplot:索引超出範圍錯誤

a = getData("/home/abuabderrahmen/caidama.csv") 
a1 = a.ix[0:,['Conductance']] 

相同的過程允許獲得陣列的任意數量。然後我使用創建我的框架對象:

e1 = concatenate((a1, b1, c1), 0) 
data1 = [e1, e1, e1[::3,0]] 

最後我用

bp = boxplot(data1, positions = [1.05, 1.35, 1.65], widths = 0.15) 

要獲得12個箱線圖繪製的箱子,我提出以下修改:

e1 = concatenate((a1, b1, c1, d1), 0) 
data1 = [e1, e1, e1[::4,0]] 
bp = boxplot(data1, positions = [1.05, 1.35, 1.65, 1.95], widths = 0.15) 

,我也得到一個列表索引超出範圍錯誤。 這種方法出了什麼問題?

+1

向我們顯示錯誤消息。 – clstaudt

+0

'.ix'在熊貓中已棄用0.20 –

回答

0

看來你可能有IndexErrorboxplot,當您嘗試繪製一個數組,其長度不等於你positions陣列的唯一案例。即:

>>> plt.boxplot([1,2,3], positions=[1.05, 1.35, 1.65, 1.95], widths = 0.15) 

Traceback (most recent call last): 
    File "<pyshell#66>", line 1, in <module> 
    plt.boxplot([1,2,3], positions=[1.05, 1.35, 1.65, 1.95], widths = 0.15) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib /pyplot.py", line 2442, in boxplot 
    usermedians=usermedians, conf_intervals=conf_intervals) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py", line 5815, in boxplot 
    d = np.ravel(x[i]) 
IndexError: list index out of range 

我懷疑你的e1[::4,0]不夠長。