Hist2d#
- class atompy.Hist2d(_H, _xedges, _yedges)[source]#
A numpy wrapper class for the return of
numpy.histogram2d().- Parameters:
- H
ndarray, shape(nx, ny) The bi-dimensional histogram as returned by np.histogram2d
- xedges
ndarray, shape(nx+1,) The bin edges along the first dimension of H
- yedges
ndarray, shape(ny+1,) The bin edges along the second dimension of H
- H
- Attributes:
HThe bi-dimensional histogram.
binareasGet areas of each bin.
column_normalized_to_maxNormalize each column to their maximum.
column_normalized_to_sumNormalize each column to their sum.
for_imshowReturn corresponding
ImshowDataobject.for_pcolormeshReturn such that it can be plotted using
histogramAlias for
Hist2d.H.normalized_to_integralNormalize histogram to it’s integral.
normalized_to_maxNormalize histogram to it’s maximum.
normalized_to_sumNormalize histogram to it’s maximum.
profile_along_xAlias for
get_profile_along_x(option="")profile_along_yAlias for
get_profile_along_y(option="")projected_onto_xProject histogram onto its x-axis
projected_onto_yProject histogram onto its y-axis
proxAlias for
projected_onto_x().proyAlias for
projected_onto_y().row_normalized_to_maxNormalize each row to their maximum.
row_normalized_to_sumNormalize each row to their sum.
without_zerosReplace zeros with
None, removing them from colormapsxbinsReturn number of xbins.
xbinwidthsReturn number of xbins.
xcentersGet center of bins along first dimension of
Hist2d.H.xedgesThe bin edges along the first dimension of Hist2d.H
ybinsReturn number of ybins.
ybinwidthsReturn number of xbins.
ycentersGet center of bins along second dimension of
Hist2d.HyedgesThe 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)