atompy.Hist2d.get_profile_along_y#

Hist2d.get_profile_along_y(option='')[source]#

Get the y-profile.

Calculate the mean value and its error per row. Which type of error is controled with option.

Parameters:
option"", "s", "i", or "g", default ""

Control type of errors, see Notes.

  • option == "": Error of the mean of all Y values

  • option == "s": Standard deviation of all Y

  • option == "i": See Notes

  • option == "g": Error of a weighted mean for combining measurements with variances of \(w\).

Returns:
hndarray

Mean values of each X (i.e., row)

errorsndarray

Errors of the mean values. Depends on option.

Notes

See TProfile of the ROOT Data Analysis Framework.

For a histogram \(X\) vs \(Y\), the following is calculated for each \(Y\) value.

\[\begin{split}\begin{align} H(j) &= \sum w X \\ E(j) &= \sum w X^2 \\ W(j) &= \sum w \\ h(j) &= H(j) / W(j) \\ s(j) &= \sqrt{E(j) / W(j) - h(j)^2} \\ e(j) &= s(j) / \sqrt{W(j)} \end{align}\end{split}\]

Here, \(w\) are the counts of bin j.

Examples

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

# get some random data
gen = np.random.default_rng(42)
x_sample = gen.normal(size=100_000)
y_sample = gen.uniform(-1, 1, size=100_000)

# create a histogram
hist = ap.Hist2d(*np.histogram2d(x_sample, y_sample,
                 bins=(100, 10), range=((-5, 5), (-1, 1))))
mean, mean_errors = hist.get_profile_along_y()
_, standard_deviation = hist.get_profile_along_y("s")

# configure plots
plt.rcParams["image.cmap"] = "atom"  # works only if atompy is imported
plt.rcParams["image.interpolation"] = "none"
plt.rcParams["image.aspect"] = "auto"

_, axs = plt.subplots(1, 2)
for ax in axs.flat:
    ax.imshow(**hist.for_imshow())
    ax.set_box_aspect(1.0)

axs[0].errorbar(mean, hist.ycenters, xerr=mean_errors)
axs[0].set_title("Errorbars = Mean errors")

axs[1].errorbar(mean, hist.ycenters, xerr=standard_deviation)
axs[1].set_title("Errorbars = Standard deviation")

ap.make_me_nice()

(Source code, png, hires.png, pdf)

../../../../_images/profile_y.png