Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test and example for plot_residual
- Loading branch information
Showing
3 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters