class colliderscope.Histogram

Constant memory histogram data structure.

Changed in version 0.2.0: Migrated from data module. Renamed _align parameter to align.

Changed in version 0.2.7: Added missed property for number of out-of-bounds updates.

Parameters:
num_bins : int

Number of bins to store multiplicities within.

window : tuple[float, float]

Range of x-axis to use for binning.

align : {"left", "center"}

Alignment of x-axis. Valid options are “left” or “center”. If "left", window will be relative to x=0. If "center", window will be centered relative to x=expected. Default is "left".

expected : float, optional

Expected value for distribution’s measure of location.

num_bins

Number of bins to store multiplicities within.

Type:

int

window

Range of x-axis values over which the histogram should track.

Type:

tuple[float, float]

align

Alignment of x-axis. Valid options are “left” or “center”. If "left", window will be relative to x=0. If "center", window will be centered relative to x=expected. Default is "left".

Type:

{“left”, “center”}

expected

Expected value for distribution’s measure of location.

Type:

float, optional

x_range

Low and high boundaries of the binned range.

Type:

tuple[float, float]

counts

Integer counts of values which entered each bin.

Type:

ndarray[int32]

bin_edges

Sequence of values defining the boundaries of the bins.

Type:

ndarray[float64]

Public members

align : 'left' | 'center' = 'left'
expected : float | None = None
__eq__(other: Self) bool

Determines if two Histogram instances contain the same bin_edges, counts, and normalisation for pdf.

__add__(other: Histogram) Histogram

Merges two Histogram instances, by adding their counts and _total normalisation variables. Must have the same bins.

property total : int
update(val) None

Records a new value to the binned counts.

to_json(fname: str | Path | IOBase, encoding: str = 'utf-8') None

Serialise and store Histogram object as a JSON file.

classmethod from_json(fname: str | Path | IOBase, ...) Histogram

Instantiate a histogram from JSON file, encoded using the Histogram.to_json() method.

property bin_width : float

The width of all bins along the x-axis.

property pdf : tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]]]

Bin centers and count density. May be used for bar chart plots.

property missed : int

Number of update values which fell out-of-bounds of the histogram’s domain.

density() ndarray[Any, dtype[float64]]

Probability density of the histogram, normalised by the total count of the histogram.

midpoints() ndarray[Any, dtype[float64]]

Midpoints of the bins along the x and y axes, respectively.

serialize() SerializedHistogram

Converts Histogram into serialized representation.

classmethod from_interface(hist: HistogramLike, ...) Self

Instantiates Histogram from a generic HistogramLike interface.

classmethod from_serialized(hist_dict: SerializedHistogram) Self

Instantiates Histogram from serialized data.

copy() Self

Returns a copy of the Histogram instance.

Histogram(num_bins: int, window: tuple[float, float], ...)

Initialize self. See help(type(self)) for accurate signature.

__repr__()

Return repr(self).

num_bins : int
window : tuple[float, float]
counts : ndarray[Any, dtype[int32]]
bin_edges : ndarray[Any, dtype[float64]]

Last update: Jun 27, 2025