.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/model_fitting/plot_residual.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_model_fitting_plot_residual.py: Plot Residual ============= Fit an affine function and plot the residual. .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python import numpy as np import hyperspy.api as hs .. GENERATED FROM PYTHON SOURCE LINES 13-14 Create a signal: .. GENERATED FROM PYTHON SOURCE LINES 14-17 .. code-block:: Python data = np.arange(1000, dtype=np.int64).reshape((10, 100)) s = hs.signals.Signal1D(data) .. GENERATED FROM PYTHON SOURCE LINES 18-19 Add noise: .. GENERATED FROM PYTHON SOURCE LINES 19-21 .. code-block:: Python s.add_poissonian_noise(random_state=0) .. GENERATED FROM PYTHON SOURCE LINES 22-23 Create model: .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: Python m = s.create_model() line = hs.model.components1D.Expression("a * x + b", name="Affine") m.append(line) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Fit for all navigation positions: .. GENERATED FROM PYTHON SOURCE LINES 29-31 .. code-block:: Python m.multifit() .. GENERATED FROM PYTHON SOURCE LINES 32-33 Plot the fitted model with residual: .. GENERATED FROM PYTHON SOURCE LINES 33-37 .. code-block:: Python m.plot(plot_residual=True) # Choose the second figure as gallery thumbnail: # sphinx_gallery_thumbnail_number = 2 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/model_fitting/images/sphx_glr_plot_residual_001.png :alt: plot residual :srcset: /auto_examples/model_fitting/images/sphx_glr_plot_residual_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/model_fitting/images/sphx_glr_plot_residual_002.png :alt: Signal :srcset: /auto_examples/model_fitting/images/sphx_glr_plot_residual_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.562 seconds) .. _sphx_glr_download_auto_examples_model_fitting_plot_residual.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_residual.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_residual.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_residual.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_