【问题标题】:Is there any way to take the data that falls outside of a historgram bin into the outermost bins?有什么方法可以将直方图 bin 之外的数据放入最外面的 bin 中?
【发布时间】:2021-11-01 20:33:34
【问题描述】:

我不太擅长编程,我正在为实验室做数据分析。我正在尝试在 Python 上生成一个带有一组 bin 的直方图,每个 bin 具有相同的 bin 宽度,理论上应该捕获所有数据。但往往有大约 10 个数据点未包含在直方图中。有没有办法将这些数据点推到最外面的 bin 中,具体取决于它们是小于还是大于直方图的整体宽度?

如果这个问题太基本或在其他地方得到了回答,我深表歉意,但我可能缺乏自己找到答案的词汇。

这是有问题的代码。我认为它使用了我的大学制作的特殊工具包,但我认为它仍然可以理解:

#sort out N by histogram
binwidth = 2.5*sig_Q
low_center = min(Q_exp) + binwidth
def set_range(first_bin = low_center, bin_width = binwidth, Nbins = 10):
     """
     helper function to set the range and bin width
     input : first_bin =  bin_center of the first bin, bin_width = the bin width, Nbins = total number of bins
     returns: a tuple that you can use in the range key word when defining a histogram.
     NOTE: for the histogram use the same number of bins:

 example:  h = histo( r, range = set_range(-5., 1, 11), bins = 11)

 this created a histogram where the first bin is centered at -5. , the next at -4. etc. a total of 11 bins are
 created and the bin center of the last one is at 5. = first_bin + (Nbins-1)*bin_width
 """
 rmin = first_bin - bin_width/2.
 rmax = rmin + Nbins*bin_width
 return (rmin,rmax)


h = B.histo(Q_exp, range = set_range(low_center, bin_width = binwidth, Nbins = 10), bins = 10)
hx = h.bin_center
hy = h.bin_content
B.pl.ylabel("Counts", fontsize = 20)
B.pl.xlabel("Gaussian Deviates", fontsize = 20)
B.pl.title("Monte Carlo Millikan Oil-Drop Simulation", fontsize = 22)
h.plot()
B.pl.show()

最好的,

【问题讨论】:

    标签: python histogram data-analysis


    【解决方案1】:

    我终于明白了。我的垃圾箱宽度太小了。一旦我延长它们并使“low_center”变小,我的数据就很好了。

    【讨论】:

      猜你喜欢
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2011-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多