在Python中从直方图获取数据点 [英] Get data points from a histogram in Python

查看:413
本文介绍了在Python中从直方图获取数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了函数的"cdf"(累积分布)的直方图.直方图基本上是计数与亮度的数量.现在,如何从直方图中提取数据点?我需要光度的实际值. 我在Python中使用Matplotlib,任何在线书籍,示例,教程等都无济于事.

I made a histogram of the 'cdf' (cumulative distribution) of a function. The histogram is basically No. of counts vs. luminosity. Now, how do I extract data points from a histogram? I need actual values of Luminosities. I am using Matplotlib in Python, and any online book, example, tutorial etc is not helping.

l= [ss.gammainccinv(aa+1, u[i]) for i in a] #is the cdf function
plt.hist(l, 50, histtype= 'step', align='mid') #is the histogram
plt.show()

我不确定是否应该将垃圾箱对准边缘或中点,但是我所需要的只是l的列表.

I am not sure if I should align the bins to the edges or the mid point, but all I need is a list of l's.

任何建议将不胜感激!

推荐答案

您已经有一个l的列表,所以我不确定最后一条语句的意思,所以也许我误解了问题.

You've already got a list of ls, so I'm not sure what you mean by that last statement, so maybe I've misinterpreted the question.

要从直方图中获取值,plt.hist会返回它们,因此您要做的就是保存它们.

To get the values from a histogram, plt.hist returns them, so all you have to do is save them.

如果不保存它们,解释器将只打印输出:

If you don't save them, the interpreter just prints the output:

In [34]: x = np.random.rand(100)

In [35]: plt.hist(x)
Out[35]: 
(array([ 11.,   9.,  10.,   6.,   8.,   8.,  10.,  10.,  11.,  17.]),
 array([ 0.00158591,  0.100731  ,  0.19987608,  0.29902116,  0.39816624,
        0.49731133,  0.59645641,  0.69560149,  0.79474657,  0.89389165,
        0.99303674]),
 <a list of 10 Patch objects>)

因此,要保存它们,请执行以下操作:

So, to save them, do:

counts, bins, bars = plt.hist(x)

这篇关于在Python中从直方图获取数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆