Python/matplotlib 在直方图中显示置信度

发布于 2024-11-11 16:38:23 字数 264 浏览 5 评论 0原文

这是我的问题。我收集了一些数据以获得“数字化”pdf,这很好。 现在,我想找到一种通过对 bin 组进行不同着色来指示不同置信区间的方法。 特别是,从包含我想要找到的最高计数的垃圾箱开始,并将面积总和小于 0.6 的所有最高垃圾箱涂上颜色(例如红色)。然后,总是通过减少计数来挑选新的垃圾箱,我想将红色区域增加到 0.8 的垃圾箱涂成橙色。 我正在考虑使用 numpy 来获取垃圾箱和计数,将它们分为 3 个系列(红色、橙色和原始颜色),并使用 pyplot 的条形图绘制它们。 希望您能指出更快的方法,谢谢!

here is my problem. I have some data I binned to obtain a "digitalised" pdf, and that's fine.
Now, I wanted to find a way to indicate different confidence intervals by coloring the bin groups differently.
In particular, starting with the bin containing the highest count I wanted to find and colour, say red, all the highest bins whose area sum to less than say .6. Then, always picking new bins by decreasing counts, i want to colour the bins who increase my red area to .8 in orange.
I was considering using numpy to get bins and counts, sort them into 3 series (red, orange and original colour) and plot them with pyplot's bar.
Hope you can point out a faster way, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左秋 2024-11-18 16:38:23

如果我正确理解你的问题,我认为下面的代码将完成你的建议。这似乎与您考虑的方法有点不同,我不确定它是否更有效。无论如何,了解别人做某事的方式通常会有所帮助。它假设已经生成了一个 pdf(直方图),其中的 bin 由变量“bins”表示,bin 宽度由变量“binwidth”表示。

gray = (.5,.5,.5)
orange = (1.0, 0.647, 0.0)
red = (1.0, 0.0, 0.0)

clrs = [gray for xx in bins]

idxs = pdf.argsort()
idxs = idxs[::-1]
oranges = idxs[(cumsum(pdf[idxs])*binwidth < 0.8).nonzero()]
reds = idxs[(cumsum(pdf[idxs])*binwidth < 0.6).nonzero()]

for idx in oranges:
    clrs[idx] = orange

for idx in reds:
    clrs[idx] = red

bar(left=bins,height=pdf,width=binwidth,color=clrs)

这是我得到的结果视图以及关联的 PDF 和 CDF

If I understand your question correctly, I think the code below will do what you are suggesting. It seems a little different than the approach you were considering, and I'm not sure it is more efficient. Regardless, it usually helps to see the way someone else would do something. It assumes an already generated pdf (histogram) with a bins represented by the varialble "bins" and bin width represented by the variable "binwidth".

gray = (.5,.5,.5)
orange = (1.0, 0.647, 0.0)
red = (1.0, 0.0, 0.0)

clrs = [gray for xx in bins]

idxs = pdf.argsort()
idxs = idxs[::-1]
oranges = idxs[(cumsum(pdf[idxs])*binwidth < 0.8).nonzero()]
reds = idxs[(cumsum(pdf[idxs])*binwidth < 0.6).nonzero()]

for idx in oranges:
    clrs[idx] = orange

for idx in reds:
    clrs[idx] = red

bar(left=bins,height=pdf,width=binwidth,color=clrs)

Here is a view of the result that I get along with the associated PDF and CDF

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文