gpt4 book ai didi

带有误差条的 Matplotlib 直方图

转载 作者:行者123 更新时间:2023-12-04 03:12:41 28 4
gpt4 key购买 nike

我用 matplotlib 创建了一个直方图使用 pyplot.hist()功能。我想在条形图中添加 bin 高度 ( sqrt(binheight) ) 的毒物误差平方根。我怎样才能做到这一点?
.hist()的返回元组包括 return[2] -> 1 个 Patch 对象的列表。我只能发现可以向通过 pyplot.bar() 创建的柱添加错误。 .

最佳答案

确实需要使用吧。您可以使用 hist 的输出并将其绘制为条形图:

import numpy as np
import pylab as plt

data = np.array(np.random.rand(1000))
y,binEdges = np.histogram(data,bins=10)
bincenters = 0.5*(binEdges[1:]+binEdges[:-1])
menStd = np.sqrt(y)
width = 0.05
plt.bar(bincenters, y, width=width, color='r', yerr=menStd)
plt.show()

enter image description here

关于带有误差条的 Matplotlib 直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774822/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com