matplotlib条带不对称误差线 [英] matplotlib bar with asymmetrical error bars

查看:88
本文介绍了matplotlib条带不对称误差线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to plot a bar graph with asymmetrical error bars...

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

The documentation of the matplotlib.pyplot.bar function says:

详细信息:xerr和yerr直接传递给errorbar(),所以它们也可以有 2xN 的形状来独立上下误差的说明.

Detail: xerr and yerr are passed directly to errorbar(), so they can also have shape 2xN for independent specification of lower and upper errors.

但是,我不能给yerr一个2xN数组...

But, I can not give an 2xN array to the yerr...

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!

并显示以下错误:

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' must be len(5) or scalar

但是,此功能代替:

import numpy as np
import matplotlib.pyplot as plt

plt.errorbar(xrange(5), [2,5,3,4,7], yerr=[[1,4,2,3,6],[4,10,6,8,14]])

工作正常.

matplotlib.pyplot.bar 是否不再支持 yerr 的 2xN 数组?如果答案是肯定的...如何绘制带有不对称误差条的条形图?

Does the matplotlib.pyplot.bar no longer support the 2xN arrays for yerr? If the answere is yes... How can I plot a bar graph with asymmetrical error bars?

感谢您的宝贵时间!

推荐答案

您正在使用哪个版本的matplotlib?

Which version of matplotlib are you using?

使用 1.1.1(最新稳定版)版本,您的代码可以完美运行.

With the 1.1.1 (latest stable) version your code work flawlessly.

这篇关于matplotlib条带不对称误差线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆