plot_spectrum#
- plot_spectrum(spectrum, ax=None, plot_mode='step', **kwargs)[source]#
Plot all spectra in a
Spectrumon a MatplotlibAxes.Is a thin wrapper of
step()orplot(). Plotsspectrum.spectral_axisandspectrum.flux. Also setsxpadto 0 by default.- Parameters:
spectrum (specutils.Spectrum) – Spectrum to plot.
spectrum.fluxmust be 1D (one line) or 2D with shape (n_spectra, n_spectral) (one line per row). All rows share the same spectral axis.ax (matplotlib.axes.Axes | None, optional, default=None) – Axes to plot on. If
None, resolved viaget_ax.plot_mode ({'step', 'plot'}, optional, default='step') –
Plotting backend, case-insensitive.
'step': callsstep().'plot': callsplot().
**kwargs – Additional keyword arguments forwarded to the selected backend (
visualastro.steporvisualastro.plot).
- Returns:
Plotted line objects, one per spectrum.
- Return type:
- Raises:
TypeError – If
spectrumis not aspecutils.Spectrum. Ifaxis not a Matplotlib Axes (raised byget_ax).ValueError – If
spectrum.fluxhas more than 2 dimensions. Ifplot_modeis not ‘step’ or ‘plot’.
Overview#
Plots a
specutils.Spectrum(spectral axis vs. flux) on a matplotlib axis.Accepts 1D or 2D flux. For 2D flux, each row is drawn as a separate line.
Returns the list of
matplotlib.lines.Line2Dartists created.
Warning
This requires the optional package specutils. See Installation Guide.
Behavior#
Use plot_mode='step' for a step plot and plot_mode='plot' for a standard line plot.
By default, xpad=0 to remove margin padding for the spectral axis (x axis). All remaining
**kwargs are forwarded to the underlying plotting function.
Examples#
Step plot of a 1D spectrum:
import matplotlib.pyplot as plt
import visualastro as va
from visualastro.core.io import example_spectrum
SN1987A_N = example_spectrum()
plt.style.use(['full', 'cm'])
va.config.show_type_label = True
va.config.show_unit_label = True
fig, ax = va.subplots(figsize=(13,5))
va.plot_spectrum(SN1987A_N, alpha=0.8, color='darkslateblue', label='NOR')
plt.show()
(Source code, svg)