Hist2d#

class atompy.Hist2d(_H, _xedges, _yedges)[source]#

A numpy wrapper class for the return of numpy.histogram2d().

Parameters:
Hndarray, shape(nx, ny)

The bi-dimensional histogram as returned by np.histogram2d

xedgesndarray, shape(nx+1,)

The bin edges along the first dimension of H

yedgesndarray, shape(ny+1,)

The bin edges along the second dimension of H

Attributes:
H

The bi-dimensional histogram.

binareas

Get areas of each bin.

column_normalized_to_max

Normalize each column to their maximum.

column_normalized_to_sum

Normalize each column to their sum.

for_imshow

Return corresponding ImshowData object.

for_pcolormesh

Return such that it can be plotted using

histogram

Alias for Hist2d.H.

normalized_to_integral

Normalize histogram to it’s integral.

normalized_to_max

Normalize histogram to it’s maximum.

normalized_to_sum

Normalize histogram to it’s maximum.

profile_along_x

Alias for get_profile_along_x(option="")

profile_along_y

Alias for get_profile_along_y(option="")

projected_onto_x

Project histogram onto its x-axis

projected_onto_y

Project histogram onto its y-axis

prox

Alias for projected_onto_x().

proy

Alias for projected_onto_y().

row_normalized_to_max

Normalize each row to their maximum.

row_normalized_to_sum

Normalize each row to their sum.

without_zeros

Replace zeros with None, removing them from colormaps

xbins

Return number of xbins.

xbinwidths

Return number of xbins.

xcenters

Get center of bins along first dimension of Hist2d.H.

xedges

The bin edges along the first dimension of Hist2d.H

ybins

Return number of ybins.

ybinwidths

Return number of xbins.

ycenters

Get center of bins along second dimension of Hist2d.H

yedges

The bin edges along the second dimension of Hist2d.H

Methods

get_profile_along_x([option])

Get the x-profile.

get_profile_along_y([option])

Get the y-profile.

rebinned_x(factor)

Rebin x-dimension of histogram.

rebinned_y(factor)

Rebin y-dimension of histogram.

save_to_file(fname, **kwargs)

Save the histogram to a file.

within_xrange(xrange[, keepdims])

Apply an inclusive gate along x.

within_yrange(yrange[, keepdims])

Apply an inclusive gate along y.

without_xrange(xrange)

Apply an exclusive gate along x.

without_yrange(yrange)

Apply an exclusive gate along y.

Examples

import numpy as np
import atompy as ap
import matplotlib.pyplot as plt

# get some random data going
rng = np.random.default_rng()
sample_x, sample_y = rng.normal(size=(2, 1_000))

# initiate a Hist2d instance
H, x, y = np.histogram2d(sample_x, sample_y)
hist2d = ap.Hist2d(H, x, y)
# or do a one-liner
hist2d = Hist2d(*np.histogram2d(sample_x, sample_y))

# plot
plt.pcolormesh(*hist2d.for_pcolormesh)

# or rebin, then plot
plt.pcolormesh(*hist2d.rebinned_x(2).for_pcolormesh)