Note
Go to the end to download the full example code.
Simple fit#
Simple gaussian fit to histogram data.

Gaussian
χ²: 83.68 / 80 dof
amplitude: 10093±33
mu: -0.0024±0.0032
sigma: 0.9956±0.0023 (min=0.0)
<matplotlib.legend.Legend object at 0x7f9d3c12b950>
import numpy as np
from aptapy.hist import Histogram1d
from aptapy.models import Gaussian
from aptapy.plotting import plt
hist = Histogram1d(np.linspace(-5., 5., 100), label="Random data", xlabel="z")
hist.fill(np.random.default_rng().normal(size=100000))
hist.plot(statistics=True)
model = Gaussian()
model.fit(hist)
print(model)
# Plot the model, including the fit output in the legend.
model.plot(fit_output=True)
plt.legend()
Total running time of the script: (0 minutes 0.313 seconds)