# pygram11.histogram2d#

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

Histogram data in two dimensions.

This function provides an API very simiar to numpy.histogram2d(). Keep in mind that the returns are different.

Parameters
• x (array_like) – Array representing the x coordinate of the data to histogram.

• y (array_like) – Array representing the y coordinate of the data to histogram.

• bins (int or array_like or [int, int] or [array, array], optional) –

The bin specification:
• If int, the number of bins for the two dimensions (nx = ny = bins).

• If array_like, the bin edges for the two dimensions (x_edges = y_edges = bins).

• If [int, int], the number of bins in each dimension (nx, ny = bins).

• If [array_like, array_like], the bin edges in each dimension (x_edges, y_edges = bins).

• range (array_like, shape(2,2), optional) – The edges of this histogram along each dimension. If bins is not integral, then this parameter is ignored. If None, the default is [[x.min(), x.max()], [y.min(), y.max()]].

• weights (array_like) – An array of weights associated to each element $$(x_i, y_i)$$ pair. Each pair of the data will contribute its associated weight to the bin count.

• flow (bool) – Include over/underflow.

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

Raises
• ValueError – If x and y have different shape or either bin edge definition is not monotonically increasing.

• ValueError – If the shape of weights is not compatible with x and y.

• TypeError – If x, y, or weights are unsupported types

fix2d

Used for no weight or single weight fixed bin width histograms

var2d

Used for no weight or single weight variable bin width histograms.

Returns

Examples

Gaussian distributions in 2D with automatic bin ranges:

>>> rng = np.random.default_rng(123)
>>> x = rng.standard_normal(size=(1000,))
>>> y = rng.standard_normal(size=(1000,))
>>> w = rng.uniform(0.3, 0.4, size=x.shape)
>>> h, err = histogram2d(x, y, bins=[10, 10], weights=w)
>>> h.shape
(10, 10)