from_centers#
- classmethod Hist1d.from_centers(values, centers, lower=None, upper=None, title='', xlabel='', ylabel='')[source]#
Initiate a
Hist1dinstance from values and bin-centers.If the bins don’t have constant size, at least one limit has to be provided, from which the edges can be determined
Attention
If centers are not the centers of all bins, or if lower or upper are not indeed the lower or upper edge, from_centers will silently produce nonsense.
- Parameters:
- centers
ndarray, shape(n) centers of the bins
- lower, uppper
float, optional Lower/upper limits of the range.
At least one limit must be provided if bins don’t have a constant size. If both lower and upper limits are provided, the lower one will be prioritized.
- title
str, default “” Optional title of the histogram.
- xlabel
str, default “” Optional x-label of the histogram.
- ylabel
str, default “” Optional y-label of the histogram.
- centers
See also
Examples
Initiate a histogram with constant bin sizes:
>>> x = 0.5, 1.5, 2.5, 3.5, 4.5 >>> y = 1, 2, 3, 4, 5 >>> hist = ap.Hist1d.from_centers(x, y) >>> hist.edges [0. 1. 2. 3. 4. 5.]
Initiate a histogram with non-constant bin sizes. Then, a lower (or upper) bound has to be passed:
>>> x = 0.5, 1.5, 3.0, 4.5, 5.5 >>> y = 1, 2, 3, 4, 5 >>> hist = ap.Hist1d.from_centers(x, y, lower=0.0) >>> hist.edges [0. 1. 2. 4. 5. 6.]