pygram11.histogram¶
-
pygram11.
histogram
(x, bins=10, range=None, weights=None, density=False, flow=False)[source]¶ Histogram data in one dimension.
- Parameters
x (array_like) – Data to histogram.
bins (int or array_like) – If int: the number of bins; if array_like: the bin edges.
range ((float, float), optional) – The minimum and maximum of the histogram axis. If
None
with integerbins
, min and max ofx
will be used. Ifbins
is an array this is expected to beNone
.weights (array_like, optional) – Weight variations for the elements of
x
. For single weight histograms the shape must be the same shape asx
. For multiweight histograms the first dimension is the length ofx
, second dimension is the number of weights variations.density (bool) – Normalize histogram counts as value of PDF such that the integral over the range is unity.
flow (bool) – Include under/overflow in the first/last bins.
- Raises
ValueError – If
bins
defines edges whilerange
is also notNone
.ValueError – If the array of bin edges is not monotonically increasing.
ValueError – If
x
andweights
have incompatible shapes.ValueError – If multiweight histogramming is detected and
weights
is not a two dimensional array.TypeError – If
x
orweights
are unsupported types
- Returns
numpy.ndarray
– The bin counts.numpy.ndarray
, optional – The standard error of each bin count, \(\sqrt{\sum_i w_i^2}\). The return isNone
if weights are not used.
See also
Examples
A simple fixed width histogram:
>>> h, __ = histogram(x, bins=20, range=(0, 100))
And with variable width histograms and weights:
>>> h, err = histogram(x, bins=[-3, -2, -1.5, 1.5, 3.5], weights=w)