From 4ef4dcbce9350ae84b126ad319de3c3af2f83bea Mon Sep 17 00:00:00 2001 From: Erik Tollerud Date: Wed, 15 Nov 2023 15:57:31 -0700 Subject: [PATCH] add quantity_support call option --- specutils/spectra/spectrum1d.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/specutils/spectra/spectrum1d.py b/specutils/spectra/spectrum1d.py index 0877d2945..a0ccf2c0b 100644 --- a/specutils/spectra/spectrum1d.py +++ b/specutils/spectra/spectrum1d.py @@ -770,7 +770,7 @@ def __repr__(self): return result def plot(self, ax=None, x_name='spectral axis', y_name='flux', - **kwargs): + set_quantity_support=True, **kwargs): """ Visualize this spectrum using matplotlib in "histogram style". @@ -785,6 +785,9 @@ def plot(self, ax=None, x_name='spectral axis', y_name='flux', y_name : str or None The name to use for the y axis (units will be automatically added) or None to not set the y axis label. + set_quantity_support : bool + If True, call `astropy.visualization.quantity_support` to ensure + that the quantities in the plot are properly settable. kwargs are passed into `~matplotlib.axes.Axes.plot`, except for ``drawstyle`` or ``ds``. @@ -798,6 +801,10 @@ def plot(self, ax=None, x_name='spectral axis', y_name='flux', # import is intentionally inside the method to make matplotlib an # "optional" dependency from matplotlib import pyplot as plt + from astropy.visualization import quantity_support + + if set_quantity_support: + quantity_support() if 'drawstyle' in kwargs or 'ds' in kwargs: raise TypeError("cannot set draw style in a spectrum's plot_quick")