.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_02_calibration_line.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_02_calibration_line.py: Calibration line ================ A thermocouple voltage is calibrated against reference temperatures. The model is a straight line; each voltage reading has its own uncertainty. .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python import numpy as np import fitwise as fw rng = np.random.default_rng(2) temperature = np.array([0.0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200]) # °C u_volt = 0.010 + 0.0002 * temperature # mV, larger at high temperatures voltage = 0.0410 * temperature - 0.02 + rng.normal(0, u_volt) result = fw.fit(fw.models.linear, temperature, voltage, yerr=u_volt) print(result) .. rst-class:: sphx-glr-script-out .. code-block:: none Model: linear(x; slope, intercept) Method: Linear least squares (direct) (auto: linear in the parameters) Converged: yes (3 evals) Data: 11 points, yerr given (absolute) Start: slope, intercept: not needed (linear model) Parameter Value ± Std.Err Rel. Bounds slope 0.04110 0.00012 0.3 % – intercept -0.0247 0.0080 32.2 % – χ²/ndf = 1.38 (9 dof, p = 0.19) R² = 0.99989 AIC = 5.3 Correlations > 0.5: slope–intercept (-0.62) Warnings: none .. GENERATED FROM PYTHON SOURCE LINES 23-26 The slope is the sensitivity of the thermocouple in mV/°C. Note the strong negative correlation between slope and intercept, listed in the report: both are estimated from the same points, so their errors are not independent. .. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: Python fig, axes = result.plot(show_params=True) axes[0].set_ylabel("voltage (mV)") axes[1].set_xlabel("temperature (°C)") .. image-sg:: /auto_examples/images/sphx_glr_plot_02_calibration_line_001.png :alt: plot 02 calibration line :srcset: /auto_examples/images/sphx_glr_plot_02_calibration_line_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 18.503588541666666, 'temperature (°C)') .. GENERATED FROM PYTHON SOURCE LINES 31-33 Because the uncertainties were given, χ²/ndf tests whether they are realistic. A value near 1 means the line describes the data within their errors. .. GENERATED FROM PYTHON SOURCE LINES 33-34 .. code-block:: Python print(f"χ²/ndf = {result.redchi:.2f}, p = {result.pvalue:.2f}") .. rst-class:: sphx-glr-script-out .. code-block:: none χ²/ndf = 1.38, p = 0.19 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.131 seconds) .. _sphx_glr_download_auto_examples_plot_02_calibration_line.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_calibration_line.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_calibration_line.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_calibration_line.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_