3

我试图在一个图中绘制大量箱线图。我成功展示了 9 个箱线图,我想获得更多箱线图。我使用了以下代码。从 csv 文件中获取数据:

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)

我得到一个列表索引超出范围错误。这种方法出了什么问题?

4

1 回答 1

0

It appears the only case you may have IndexError is in boxplot, when you try to plot an array whose length is not equal to that of your positions array. i.e.:

>>> 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

I suspect your e1[::4,0] is not long enough.

于 2013-09-25T15:28:01.373 回答