相关疑难解决方法(0)

matplotlib条带有不对称误差条

我需要绘制一个带有不对称误差条的条形图...

matplotlib.pyplot.bar函数的文档说:

细节:xerr和yerr直接传递给errorbar(),因此它们也可以具有形状2xN,用于独立指定低位和高位错误.

但是,我不能给一个2xN阵列...

import numpy as np
import matplotlib.pyplot as plt

plt.bar(xrange(5), [2,5,3,4,7], yerr=[[1,4,2,3,6],[4,10,6,8,14]]) #DO NOT work!
Run Code Online (Sandbox Code Playgroud)

并告诉我以下错误:

Traceback (most recent call last):
  File "bar_stacked.py", line 9, in <module>
    plt.bar(xrange(5), [2,5,3,4,7], yerr=[[1,4,2,3,6],[4,10,6,8,14]])
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 1742, in bar
    ret = ax.bar(left, height, width, bottom, color, edgecolor, linewidth, yerr, xerr, ecolor, capsize, align, orientation, log, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 4253, in bar
    "incompatible sizes: bar() argument 'yerr' must be len(%s) or scalar" % nbars)
ValueError: incompatible sizes: bar() argument 'yerr' …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

matplotlib ×1

python ×1