带字典列表的错误栏的直方图

时间:2015-10-26 11:16:52

标签: python list dictionary matplotlib

数据:

 [OrderedDict([(u'X1', 1), (u'X2', 21), (u'X3', 47), (u'X4', 18)]),
 OrderedDict([(u'X1', 25), (u'X2', 41), (u'X3', 16), (u'X4', 5)]),
 OrderedDict([(u'X1', 5), (u'X2', 23), (u'X3', 54), (u'X4', 5)]),
 OrderedDict([(u'X1', 0), (u'X2', 33), (u'X3', 43), (u'X4', 11)]),
 OrderedDict([(u'X1', 2), (u'X2', 41), (u'X3', 30), (u'X4', 14)]),
 OrderedDict([(u'X1', 16), (u'X2', 38), (u'X3', 22), (u'X4', 11)])]

如何从中创建带有错误栏的直方图? 例如: enter image description here

来自dict的简单的histrogram:

import pylab as pl
import matplotlib.pyplot as plt
def histogram_plots(d,filename):
    X = np.arange(len(d))
    pl.bar(X, d.values(), align='center', width=0.5)
    pl.xticks(X, d.keys())
    ymax = max(d.values()) + 1
    pl.ylim(0, ymax)
    print d.keys()
    plt.savefig('..\histograms\\'+filename)  #  plt.savefig('.\histograms\\'+'_'.join(d.keys()))

1 个答案:

答案 0 :(得分:1)

您的答案就在pyplot.bar docs中:您只需使用yerr参数传递错误栏即可。