baldaquin.hist — Histograms#

Module documentation#

Histogram facilities.

exception baldaquin.hist.InvalidShapeError(expected, actual)[source]#

RuntimeError subclass to signal an invalid shape while operating with arrays.

class baldaquin.hist.HistogramBase(binning, labels)[source]#

Base class for an n-dimensional histogram.

This interface to histograms is profoundly different for the minimal numpy/matplotlib approach, where histogramming methods return bare vectors of bin edges and counts.

Note that this base class is not meant to be instantiated directly, and the interfaces to concrete histograms of specific dimensionality are defined in the sub-classes.

Parameters:
  • binning (n-dimensional tuple of arrays) – the bin edges on the different axes.

  • labels (n-dimensional tuple of strings) – the text labels for the different axes.

PLOT_OPTIONS = {}#
_zeros(dtype: type = <class 'float'>)[source]#

Return an array of zeros of the proper shape for the underlying histograms quantities.

reset() None[source]#

Reset the histogram.

bin_centers(axis: int = 0) array[source]#

Return the bin centers for a specific axis.

bin_widths(axis: int = 0) array[source]#

Return the bin widths for a specific axis.

errors() array[source]#

Return the errors on the bin content.

set_axis_label(axis: int, label: str) None[source]#

Set the label for a given axis.

static calculate_axis_statistics(bin_centers: array, content: array) dict[source]#

Calculate the basic statistics (normalization, mean and rms) for a given set of binned data.

_check_array_shape(data: array) None[source]#

Check the shape of a given array used to update the histogram.

set_errors(errors: array) None[source]#

Set the proper value for the _sumw2 underlying array, given the errors on the bin content.

fill(*values, weights=None)[source]#

Fill the histogram from unbinned data.

Note this method is returning the histogram instance, so that the function call can be chained.

set_content(content: array, entries: array | None = None, errors: array | None = None)[source]#

Set the bin contents programmatically from binned data.

Note this method is returning the histogram instance, so that the function call can be chained.

static bisect(binning: array, values: array, side: str = 'left') array[source]#

Return the indices corresponding to a given array of values for a given binning.

find_bin(*coords)[source]#

Find the bin corresponding to a given set of “physical” coordinates on the histogram axes.

This returns a tuple of integer indices that can be used to address the histogram content.

find_bin_value(*coords)[source]#

Find the histogram content corresponding to a given set of “physical” coordinates on the histogram axes.

normalization(axis: int | None = None)[source]#

return the sum of weights in the histogram.

empty_copy()[source]#

Create an empty copy of a histogram.

copy()[source]#

Create a full copy of a histogram.

_plot(**kwargs) None[source]#

No-op plot() method, to be overloaded by derived classes.

plot(axes=None, **kwargs) None[source]#

Plot the histogram.

class baldaquin.hist.Histogram1d(xbinning: array, xlabel: str = '', ylabel: str = 'Entries/bin')[source]#

A one-dimensional histogram.

PLOT_OPTIONS = {'alpha': 0.4, 'histtype': 'stepfilled', 'lw': 1.25}#
current_stats() dict[source]#

Calculate the basic binned statistics for the histogram.

stat_box(axes=None) None[source]#

Draw a stat box for the histogram.

_plot(axes, **kwargs) None[source]#

Overloaded make_plot() method.

class baldaquin.hist.Histogram2d(xbinning, ybinning, xlabel='', ylabel='', zlabel='Entries/bin')[source]#

A two-dimensional histogram.

PLOT_OPTIONS = {'cmap': <matplotlib.colors.LinearSegmentedColormap object>}#
_plot(axes, logz=False, **kwargs)[source]#

Overloaded make_plot() method.

slice(bin_index: int, axis: int = 0)[source]#

Return a slice of the two-dimensional histogram along the given axis.

slices(axis: int = 0)[source]#

Return all the slices along a given axis.

hslice(bin_index: int)[source]#

Return the horizontal slice for a given bin.

hslices()[source]#

Return a list of all the horizontal slices.

hbisect(y: float)[source]#

Return the horizontal slice corresponding to a given y value.

vslice(bin_index)[source]#

Return the vertical slice for a given bin.

vslices()[source]#

Return a list of all the vertical slices.

vbisect(x)[source]#

Return the vertical slice corresponding to a given y value.