You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In high energy physics (HEP), histograms are often displayed as a collection of
data points, one for each bin. This allows one to easily compare the data to
an underlying probability model.
It can be debated if it is correct to attach error bars to the individual bin
contents as opposed to the underlying model, as we want to know if our
expectation for any given bin could fluctuate to match the data and not vice
versa. But this is a convention widely used by the HEP community, and thus a
way to use this kind of plot in Python is often necessary.
A simple way to create these kinds of plots is missing from other Python
packages like matplotlib. The histpoints function is designed to produce
these plots conventiently, like in the following example:
Or, displaying horizontal error bars to mark the bin width:
histpoints(data, xerr='binwidth')
Note that the histpoints function returns the x and y coordinates of the
points, as well as norm, the integral of the histogram. This can be used to
scale a probability distribution to the histogram, as opposed to the other way
around, like in the example above.
This is often preferred in HEP, as it allows you to gauge the amount of entries
in your data sample more easily.
By default, histpoints chooses the number of bins automatically via the
Freedman-Diaconis
rule.