-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add plot function for guidance spectra (#92)
* 👌 Prevent crash of plot_fitted_traces when guidance spectrum in result * ✨ Added 'plot_guidance' function * 👌 Fall back to plot_guidance in plot_overview for guidance spectrum instead of crashing * 🩹 Respect figure_only argument for guidance case in plot_overview
- Loading branch information
Showing
4 changed files
with
80 additions
and
6 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
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,65 @@ | ||
"""Module containing guidance spectra plotting functionality.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from pyglotaran_extras.io.load_data import load_data | ||
from pyglotaran_extras.plotting.style import PlotStyle | ||
from pyglotaran_extras.plotting.utils import add_cycler_if_not_none | ||
|
||
if TYPE_CHECKING: | ||
from cycler import Cycler | ||
from matplotlib.figure import Figure | ||
from matplotlib.pyplot import Axes | ||
|
||
from pyglotaran_extras.types import DatasetConvertible | ||
|
||
|
||
def plot_guidance( | ||
result: DatasetConvertible, | ||
figsize: tuple[int, int] = (15, 5), | ||
title: str = "Guidance Overview", | ||
y_label: str = "a.u.", | ||
cycler: Cycler | None = PlotStyle().cycler, | ||
) -> tuple[Figure, Axes]: | ||
"""Plot overview for a guidance spectrum. | ||
Parameters | ||
---------- | ||
result: DatasetConvertible | ||
Result from a pyglotaran optimization as dataset, Path or Result object. | ||
figsize: tuple[int, int] | ||
Size of the figure (N, M) in inches. Defaults to (15, 5) | ||
title: str | ||
Title to add to the figure. Defaults to "Guidance Overview" | ||
y_label: str | ||
Label used for the y-axis of each subplot. Defaults to "a.u." | ||
cycler: Cycler | None | ||
Plot style cycler to use. Defaults to PlotStyle().cycler. | ||
Returns | ||
------- | ||
tuple[Figure, Axes] | ||
Figure and axes which can then be refined by the user. | ||
""" | ||
res = load_data(result) | ||
fig, axes = plt.subplots(1, 2, figsize=figsize) | ||
|
||
for axis in axes: | ||
add_cycler_if_not_none(axis, cycler) | ||
|
||
res.data.plot(x="spectral", ax=axes[0], label="data") | ||
res.fitted_data.plot(x="spectral", ax=axes[0], label="fit") | ||
res.residual.plot(x="spectral", ax=axes[1], label="residual") | ||
|
||
for axis in axes: | ||
axis.set_ylabel(y_label) | ||
axes[0].legend() | ||
axes[0].set_title("Fit quality") | ||
axes[1].set_title("Residual") | ||
fig.suptitle(title, fontsize=28) | ||
plt.tight_layout() | ||
|
||
return fig, axes |
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