Plotting¶
Note
Requires matplotlib: pip install pyspectrakit[plot]
spectrakit.plot.plot_spectrum ¶
plot_spectrum(
intensities: ndarray,
wavenumbers: ndarray | None = None,
*,
ax: Axes | None = None,
title: str | None = None,
xlabel: str = "Wavenumber",
ylabel: str = "Intensity",
invert_x: bool = True,
labels: list[str] | None = None,
**kwargs: Any,
) -> Axes
Plot one or more spectra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Spectral data, shape |
required |
wavenumbers
|
ndarray | None
|
Wavenumber axis, shape |
None
|
ax
|
Axes | None
|
Matplotlib Axes to plot on. If None, creates a new figure. |
None
|
title
|
str | None
|
Plot title. |
None
|
xlabel
|
str
|
X-axis label. |
'Wavenumber'
|
ylabel
|
str
|
Y-axis label. |
'Intensity'
|
invert_x
|
bool
|
Whether to invert the x-axis (standard for IR spectra). |
True
|
labels
|
list[str] | None
|
Legend labels for each spectrum. Only used for 2D input. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib Axes object. |
Source code in src/spectrakit/plot.py
spectrakit.plot.plot_comparison ¶
plot_comparison(
original: ndarray,
processed: ndarray,
wavenumbers: ndarray | None = None,
*,
ax: Axes | None = None,
labels: tuple[str, str] = ("Original", "Processed"),
title: str | None = None,
xlabel: str = "Wavenumber",
ylabel: str = "Intensity",
invert_x: bool = True,
**kwargs: Any,
) -> Axes
Plot before/after comparison of spectral processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
ndarray
|
Original spectrum, shape |
required |
processed
|
ndarray
|
Processed spectrum, shape |
required |
wavenumbers
|
ndarray | None
|
Wavenumber axis, shape |
None
|
ax
|
Axes | None
|
Matplotlib Axes to plot on. If None, creates a new figure. |
None
|
labels
|
tuple[str, str]
|
Legend labels for original and processed spectra. |
('Original', 'Processed')
|
title
|
str | None
|
Plot title. |
None
|
xlabel
|
str
|
X-axis label. |
'Wavenumber'
|
ylabel
|
str
|
Y-axis label. |
'Intensity'
|
invert_x
|
bool
|
Whether to invert the x-axis. |
True
|
**kwargs
|
Any
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib Axes object. |
Source code in src/spectrakit/plot.py
spectrakit.plot.plot_baseline ¶
plot_baseline(
intensities: ndarray,
baseline: ndarray,
wavenumbers: ndarray | None = None,
*,
ax: Axes | None = None,
show_corrected: bool = True,
title: str | None = None,
xlabel: str = "Wavenumber",
ylabel: str = "Intensity",
invert_x: bool = True,
**kwargs: Any,
) -> Axes
Plot a spectrum with its estimated baseline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensities
|
ndarray
|
Original spectrum, shape |
required |
baseline
|
ndarray
|
Estimated baseline, shape |
required |
wavenumbers
|
ndarray | None
|
Wavenumber axis, shape |
None
|
ax
|
Axes | None
|
Matplotlib Axes to plot on. If None, creates a new figure. |
None
|
show_corrected
|
bool
|
If True, also plots the corrected spectrum. |
True
|
title
|
str | None
|
Plot title. |
None
|
xlabel
|
str
|
X-axis label. |
'Wavenumber'
|
ylabel
|
str
|
Y-axis label. |
'Intensity'
|
invert_x
|
bool
|
Whether to invert the x-axis. |
True
|
**kwargs
|
Any
|
Additional keyword arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib Axes object. |