histogram2d

sherpa.utils.histogram2d(x, y, x_grid, y_grid)[source] [edit on github]

Create 2D histogram from a sequence of samples.

See the numpy.histogram2d routine for a version with more options.

Changed in version 4.15.0: The x_grid and y_grid arguments are no-longer changed (sorted) by this routine.

Parameters:
xsequence of numbers

The array of samples (X coordinate)

ysequence of numbers

The array of samples (Y coordinate), which must have the same size as the x sequence.

x_gridsequence of numbers

The X bin edges.

y_gridsequence of numbers

The Y bin edges.

Returns:
yNumPy array

The number of samples in each histogram bin defined by the x_grid and y_grid arrays.

Examples

Given a list of coordinates (xvals, yvals), bin them up so that they match the 5 by 10 pixel image data space. In this case the X grid is [1, 2, …, 5] and the Y grid is [1, 2, .., 10].

>>> from sherpa.utils import dataspace2d, histogram2d
>>> d2 = dataspace2d([5, 10])
>>> hist = histogram2d([1.2, 1.3, 3.4], [2.2, 1.1, 5.5], d2[0], d2[1])