.. 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() .. rst-class:: sphx-glr-script-out .. code-block:: none Exception ignored in: Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/tqdm/std.py", line 1148, in __del__ self.close() File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/tqdm/notebook.py", line 279, in close self.disp(bar_style='danger', check_delay=False) ^^^^^^^^^ AttributeError: 'tqdm_notebook' object has no attribute 'disp' 0%| | 0/10 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_residual.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_