有什么方法可以将落在直方图 bin 之外的数据放入最外面的 bins 中吗?

Is there any way to take the data that falls outside of a historgram bin into the outermost bins?

我不太擅长编程,我正在为实验室做数据分析。我正在尝试在 Python 上生成一个直方图,其中包含一定数量的箱子,每个箱子具有相同的箱子宽度,理论上应该捕获所有数据。但往往有大约 10 个数据点未包含在直方图中。有什么方法可以根据它们是小于还是大于直方图的总宽度将这些数据点推入最外面的容器中?

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

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

#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()

最佳,

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