pygram11.bin_centers

pygram11.bin_centers(bins, range=None)[source]

Construct array of center values for each bin.

Parameters
  • bins (int or array_like) – Number of bins or bin edges array.

  • range ((float, float), optional) – The minimum and maximum of the histogram axis.

Returns

Array of bin centers.

Return type

numpy.ndarray

Raises

ValueError – If bins is an integer and range is undefined (None).

Examples

The centers given the number of bins and max/min:

>>> bin_centers(10, range=(-3, 3))
array([-2.7, -2.1, -1.5, -0.9, -0.3,  0.3,  0.9,  1.5,  2.1,  2.7])

Or given bin edges:

>>> bin_centers([0, 1, 2, 3, 4])
array([0.5, 1.5, 2.5, 3.5])