pygram11.fix2d(x, y, bins=10, range=None, weights=None, flow=False, cons_var=False)[source]#

Histogram two dimensional data with fixed (uniform) binning.

The two input arrays (x and y) must be the same length (shape).

  • x (numpy.ndarray) – First entries in data pairs to histogram.

  • y (numpy.ndarray) – Second entries in data pairs to histogram.

  • bins (int or (int, int)) – If int, both dimensions will have that many bins; if tuple, the number of bins for each dimension

  • range (Sequence[Tuple[float, float]], optional) – Axis limits in the form [(xmin, xmax), (ymin, ymax)]. If None the input data min and max will be used.

  • weights (array_like, optional) – The weights for data element. If weights are absent, the second return type will be None.

  • flow (bool) – Include over/underflow.

  • cons_var (bool) – If True, conserve the variance rather than return the standard error (square root of the variance).

  • ValueError – If x and y have incompatible shapes.

  • ValueError – If the shape of weights is incompatible with x and y

  • TypeError – If x, y, 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.


A histogram of (x, y) with 20 bins between 0 and 100 in the x dimention and 10 bins between 0 and 50 in the y dimension:

>>> rng = np.random.default_rng(123)
>>> x = rng.uniform(0, 100, size=(200,))
>>> y = rng.uniform(0, 50, size=(200,))
>>> h, __ = fix2d(x, y, bins=(20, 10), range=((0, 100), (0, 50)))

The same data, now histogrammed weighted (via w):

>>> w = rng.uniform(0.2, 0.9, size=x.shape)
>>> h, err = fix2d(x, y, bins=(20, 10), range=((0, 100), (0, 50)), weights=w)