Hist1d#

class atompy.Hist1d(values, edges, title='', xlabel='', ylabel='')[source]#

A histogram class providing basic histogram methods.

Tip

Histogram your data using numpy.histogram(), then wrap the results in Hist1d:

hist = ap.Hist1d(*np.histogram(data))
Parameters:
valuesarray_like

The histogram values, e.g., counts.

edgesarray_like

The edges of the histogram bins. Note that len(values) = len(edges) + 1

Note

If you want to initialize a Hist1d from centers instead of edges, use Hist1d.from_centers().

titlestr, default “”

Optional title of the histogram.

xlabelstr, default “”

Optional x-label of the histogram.

ylabelstr, default “”

Optional y-label of the histogram.

Attributes:
edgesndarray

Edges of the histogram’s bins.

bin_edgesndarray

Alias for Hist1d.edges

valuesndarray

Histogram’s values (e.g., counts).

histndarray

Alias for Hist1d.values

centersndarray

Centers of the histogram’s bins.

limits(float, float)

Limits of the histogram’s edges.

nbinsint

Number of bins.

labels_dictdict

A dictionary of the histogram’s title, xlabel and ylabel.

Methods

binsizes()

Return the widths of all bins.

convert_cosine_to_angles([full_range])

Convert edges which represent cosine(angle) to angle.

copy()

Return a copy of the histogram.

for_bar()

Return arrays appropriate for plotting with plt.bar.

for_plot()

Return arrays appropriate for plotting with plt.plot.

for_step([extent_to])

Return arrays appropriate for plotting with plt.step.

from_centers(values, centers[, lower, ...])

Initiate a Hist1d instance from values and bin-centers.

from_root(fname, hname[, title, xlabel, ylabel])

Initiate a Hist1d from a ROOT file.

from_txt(fname[, data_layout, idx_centers, ...])

Initiate a Hist1d from a text file.

integrate()

Return the integral of the histogram.

keep(lower, upper[, squeeze, setval])

Keep every entry of the histogram in-between lower and upper

max()

Return the maximum value of the histogram.

min()

Return the minimum value of the histogram.

norm_diff(other)

Return the normalized difference between two histograms.

norm_to_integral()

Return the histogram normalized to Hist1d.integrate().

norm_to_max()

Return the histogram normalized to Hist1d.max().

norm_to_sum()

Return the histogram normalized to Hist1d.sum().

pad_with(value)

Extent histogram left and right with value.

plot([ax, fname, xlabel, ylabel, title, ...])

Plot the 1D histogram using matplotlib.pyplot.plot.

plot_step([ax, fname, xlabel, ylabel, ...])

Plot the 1D histogram using matplotlib.pyplot.plot.

rebin(factor)

Rebin histogram.

remove(lower, upper[, setval])

Remove every entry of the histogram in-between lower and upper

sum()

Return the sum of the histogram's values.