.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_01_gaussian_peak.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_01_gaussian_peak.py: Gaussian peak in three lines ============================ The shortest possible fit: a built-in model, data with uncertainties, a report and a plot. No starting values are needed; fitwise estimates them from the data. .. GENERATED FROM PYTHON SOURCE LINES 10-11 Simulated measurement: a Gaussian peak with known noise of 0.05. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python import numpy as np rng = np.random.default_rng(1) x = np.linspace(-4, 6, 80) y = 3.2 * np.exp(-((x - 1.1) ** 2) / (2 * 0.8**2)) + rng.normal(0, 0.05, x.size) dy = np.full_like(x, 0.05) .. GENERATED FROM PYTHON SOURCE LINES 19-20 The fit itself: .. GENERATED FROM PYTHON SOURCE LINES 20-25 .. code-block:: Python import fitwise as fw result = fw.fit(fw.models.gaussian, x, y, yerr=dy) print(result) .. rst-class:: sphx-glr-script-out .. code-block:: none Model: gaussian(x; amp, cen, sigma) Method: Trust Region Reflective (scipy least_squares) (auto: nonlinear) Converged: yes (13 evals) Data: 80 points, yerr given (absolute) Start: amp, cen, sigma: peak heuristic Parameter Value ± Std.Err Rel. Bounds amp 3.179 0.018 0.6 % – cen 1.0984 0.0053 0.5 % – sigma 0.8057 0.0053 0.7 % – χ²/ndf = 0.718 (77 dof, p = 0.97) R² = 0.9983 AIC = -23.6 Correlations > 0.5: amp–sigma (-0.58) Warnings: none .. GENERATED FROM PYTHON SOURCE LINES 26-27 ``plot()`` shows the data, the fit and the residuals in units of ``yerr``. .. GENERATED FROM PYTHON SOURCE LINES 27-29 .. code-block:: Python fig, axes = result.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_01_gaussian_peak_001.png :alt: plot 01 gaussian peak :srcset: /auto_examples/images/sphx_glr_plot_01_gaussian_peak_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 30-31 Individual parameters are available by name, with value and standard error: .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: Python sigma = result.params["sigma"] print(f"FWHM = {2.3548 * sigma.value:.3f} ± {2.3548 * sigma.stderr:.3f}") .. rst-class:: sphx-glr-script-out .. code-block:: none FWHM = 1.897 ± 0.013 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.160 seconds) .. _sphx_glr_download_auto_examples_plot_01_gaussian_peak.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_gaussian_peak.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_gaussian_peak.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_gaussian_peak.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_