diff --git a/examples/model_fitting/plot_residual.py b/examples/model_fitting/plot_residual.py new file mode 100644 index 0000000000..e499356fba --- /dev/null +++ b/examples/model_fitting/plot_residual.py @@ -0,0 +1,36 @@ +""" +Plot Residual +============= + +Fit an affine function and plot the residual. + +""" + +import numpy as np +import hyperspy.api as hs + +#%% +# Create a signal: +data = np.arange(1000, dtype=np.int64).reshape((10, 100)) +s = hs.signals.Signal1D(data) + +#%% +# Add noise: +s.add_poissonian_noise(random_state=0) + +#%% +# Create model: +m = s.create_model() +line = hs.model.components1D.Expression("a * x + b", name="Affine") +m.append(line) + +#%% +# Fit for all navigation positions: +m.multifit() + +#%% +# Plot the fitted model with residual: +m.plot(plot_residual=True) + +#%% +# sphinx_gallery_thumbnail_number = 2 diff --git a/hyperspy/tests/drawing/test_plot_model1d.py b/hyperspy/tests/drawing/test_plot_model1d.py index d6799e31d3..3689b14af3 100644 --- a/hyperspy/tests/drawing/test_plot_model1d.py +++ b/hyperspy/tests/drawing/test_plot_model1d.py @@ -29,7 +29,7 @@ class TestModelPlot: def setup_method(self, method): - s = Signal1D(np.arange(1000).reshape((10, 100))) + s = Signal1D(np.arange(1000, dtype=np.int64).reshape((10, 100))) s.add_poissonian_noise(random_state=0) m = s.create_model() line = Expression("a * x", name="line", a=1) @@ -64,3 +64,6 @@ def test_default_navigator_plot(self): def test_no_navigator(self): self.m.plot(navigator=None) assert self.m.signal._plot.navigator_plot is None + + def test_plot_residual(self): + self.m.plot(plot_residual=True) diff --git a/hyperspy/tests/model/test_model.py b/hyperspy/tests/model/test_model.py index 8e5d93f988..206ae65165 100644 --- a/hyperspy/tests/model/test_model.py +++ b/hyperspy/tests/model/test_model.py @@ -23,7 +23,6 @@ import hyperspy.api as hs from hyperspy.decorators import lazifyTestClass -from hyperspy.misc.test_utils import ignore_warning from hyperspy.misc.utils import slugify