简体   繁体   English

为多个元素创建具有均值和标准差的直方图

[英]Create histogram with mean and standard deviation for multiples elements

The array below consists of the following structure:下面的数组由以下结构组成:

Array:大批:

[[[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

I am trying to generate an output in matplotlib where the graph is a histogram with the following structure:我正在尝试在 matplotlib 中生成matplotlib ,其中该图是具有以下结构的直方图:

在此处输入图像描述

1 bar with the mean and the next to the side a bar with the standard deviation, following this order until the end of the block, which are composed of 5 means and 5 standard deviations 1 个带有平均值的条形图,旁边一个带有标准偏差的条形图,按照此顺序直到块结束,由 5 个均值和 5 个标准差组成

I tested something like:我测试了类似的东西:

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

Note: The number of sublist with mean and standard deviation is relative to the size of the date set, the example array is generated by a function that consumes this data注意:具有平均值和标准差的子列表的数量与日期集的大小有关,示例数组由使用此数据的 function 生成

Y Axis should range from 0 to 100, and it will not be often that the value will be repeated Y轴应该在0到100的范围内,不会经常重复值

I would do:我会做:

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([]);

Output: Output:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM