【问题标题】:Create histogram with mean and standard deviation for multiples elements为多个元素创建具有均值和标准差的直方图
【发布时间】:2020-06-04 23:35:30
【问题描述】:

下面的数组由以下结构组成:

数组:

[[[70, 2.23606797749979], [66, 5.477225575051661], [71, 1.4142135623730951], [75, 4.58257569495584], [68, 0.0]], [[78, 5.196152422706632], [69, 2.0], [69, 2.0], [69, 2.0], [69, 2.0]]]

[[[Average, Standard deviation],[Average, Standard deviation]],[ ... ]]] --> Block

我正在尝试在matplotlib 中生成输出,其中图表是具有以下结构的直方图:

1 个带平均值的柱形图,旁边一个带标准差的柱形图,按照此顺序直到块结束,由 5 个均值和 5 个标准差组成

我测试了类似的东西:

x = [[Mean], [Standard Deviation]]
colors = ['red', 'lime']
plt.hist(x, n_bins, density=True, histtype='bar', color=colors, label=colors)

注意:具有均值和标准差的子列表的数量与日期集的大小有关,示例数组由消耗此数据的函数生成

Y轴的范围应该是0到100,值不会经常重复

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我愿意:

    fig, ax = plt.subplots(figsize=(10,6))
    for i in range(2):
        data = a[i]
        x=np.arange(len(data)) + i*6
        # draw means
        ax.bar(x-0.2, data[:,0], color='C0', width=0.4)
    
        # draw std
        ax.bar(x+0.2, data[:,1], color='C1', width=0.4)
    
    # separation line
    ax.axvline(4.75)
    
    # turn off xticks
    ax.set_xticks([]);
    

    输出:

    【讨论】:

      猜你喜欢
      • 2012-10-15
      • 2014-01-07
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 2020-12-26
      • 2014-04-27
      • 2014-09-04
      相关资源
      最近更新 更多