- pygram11.histogram(x, bins=10, range=None, weights=None, density=False, flow=False, cons_var=False)#
Histogram data in one dimension.
x (array_like) – Data to histogram.
bins (int or array_like) – If int: the number of bins; if array_like: the bin edges.
weights (array_like, optional) – Weight variations for the elements of x. For single weight histograms the shape must be the same shape as x. For multiweight histograms the first dimension is the length of x, 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.
cons_var (bool) – If
True, conserve the variance rather than return the standard error (square root of the variance).
ValueError – If bins defines edges while range is also not
ValueError – If the array of bin edges is not monotonically increasing.
ValueError – If x and weights have incompatible shapes.
ValueError – If multiweight histogramming is detected and weights is not a two dimensional array.
TypeError – If x or weights are unsupported types
A simple fixed width histogram:
>>> rng = np.random.default_rng(123) >>> x = rng.standard_normal(2000) >>> h, __ = histogram(x, bins=20, range=(-3, 3))
And with variable width histograms and weights:
>>> w = rng.uniform(0.3, 1.1, size=x.shape) >>> h, err = histogram(x, bins=[-3, -2, -1.5, 1.5, 3.5], weights=w)