Creating Histograms

There is a generic Histograms Model (HistModel) that can be used for binning values, saving the histogram to a dataset, and viewing the data in an applet.

To use the model, first instantiate an instance, specify the bin boundaries, and initialize the datasets:

model = HistModel(self, namespace='my_histogram')

## Binning single values ## To bin a single value use the bin_value() method:


After you are done binning, call the set_bins() method to write the histogram to it’s dataset which will be named bins under the model namespace:

model.set_bins() # write data to 'my_histogram.bins'

To clear out the histogram and start binning new values, e.g. for a new measurement or datapoint, call the reset_bins() method


Binning multiple values at once

To bin multiple values and set the bins dataset all in one go, use the mutate() method.

model.mutate([42, 42, 42, 42, 42, 41, 43], broadcast=True, persist=False, save=False)

Binning Continuous Values

By default, the HistModel class assumes the data being binned is discretely valued such as from PMT counts. Non-discrete values can also be binned by setting the model’s discrete attribute to False.


In addition to the binned data, initialize_datasets() sets datasets that can be used in plots: x_units, x_label, y_label, and plot_title. Values are defined through model attributes:

model = HistModel(self,
    x_label="PMT Counts",
    plot_title="My Plot",
model.initialize_datasets()  # set's `my_histogram.x_label` to "PMT Counts" & `my_histogram.plot_title` to "My Plot"