pygram11.var1d(x, bins, weights=None, density=False, flow=False, cons_var=False)[source]#

Histogram data with variable bin widths.

  • x (numpy.ndarray) – Data to histogram

  • bins (numpy.ndarray) – Bin edges

  • weights (numpy.ndarray, optional) – The weights for each element of x. If weights are absent, the second return type will be None.

  • 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 the array of bin edges is not monotonically increasing.

  • ValueError – If x and weights have incompatible shapes.

  • TypeError – If x or weights are unsupported types


  • numpy.ndarray – The bin counts.

  • numpy.ndarray, optional – The standard error of each bin count, \(\sqrt{\sum_i w_i^2}\). If cons_var is True, the variances are returned. The return is None if weights are not used.


A simple histogram with variable width bins:

>>> rng = np.random.default_rng(123)
>>> x = rng.standard_normal(1000)
>>> edges = np.array([-3.0, -2.5, -1.5, -0.25, 0.25, 2.0, 3.0])
>>> h, __ = var1d(x, edges)