【发布时间】:2015-03-05 03:26:18
【问题描述】:
当我尝试调整箱线图中的胡须长度时,我遇到了一个令人困惑的错误——我希望使用 kwarg whis = [5,95] 让胡须从第 5 个百分位值延伸到第 95 个百分位值。当我这样做时,我收到以下错误(复制整个回溯):
> Traceback (most recent call last):
> File "boxplot_snoho_bc.py", line 125, in <module>
> main()
> File "boxplot_snoho_bc.py", line 64, in main
> bp = boxplot(data[0], positions = [1], widths = 0.6, whis = [5,95])
> File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2143, in boxplot
> ret = ax.boxplot(x, notch, sym, vert, whis, positions, widths, patch_artist, bootstrap)
> File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 5545, in
> boxplot
> wisk_hi = np.compress( d <= hi_val , d )
> ValueError: operands could not be broadcast together with shapes (10) (42)
我从其他线程和帮助文档的理解是,这是正确的语法,但我是 python 新手,可能会出错......
为了清楚起见,这里是导致错误的命令:
bp = 箱线图(数据[0],位置 = [1],宽度 = 0.6,whis = [5,95])
data 是一个 8x10 的 numpy 数组;我一次只绘制一个框。这是数组的样子:
打印数据
[[40.66 33.53 30.56 30.83 11.8 60.91 11.91 10.74 23.97 11.]
[16.19 85.69 206.25 27.16 29.22 41.69 16.44 10.41 477.75 23.95]
[1651.192.16.02 29.91 14.95 123.38 31.22 11.08 29.5 16.03]
[132.5 874.5 12.51 41.5 68.25 60.22 36.91 12.27 58.84 28.33]
[145.5 26.95 25.2 33.88 44.78 40.16 16.78 18.95 36.03 16.05]
[18.89 82.94 83.56 344.118.94 49.62 23.23 25.89 2072.90.56]
[221.38 22.69 35.28 25.08 25.16 41.84 16.77 14.16 12.77 15.27]
[32.03 1634.34.59 140.12 61.22 32.53 24.55 20.06 30.97 27.14]]
【问题讨论】: