Plotting Functions

This package provides convenience plotting functions for visualizing and interpreting X-ray spectra. It relies on the matplotlib plotting infrastructure.

All functions take a Matplotlib AxesSubplot object object as the primary argument. We recommend setting up the Axes object using the matplotlib.pyplot.subplot function. For example, to set up axes for a single plot window:

import matplotlib.pyplot as plt
ax = plt.subplot(111)

Plot a counts histogram

pyxsis.plot.plot_counts(ax, spectrum, xunit='keV', perbin=True, rate=False, plot_bkg=False, subtract_bkg=True, use_backscale=True, scale_factor=1.0, **kwargs)[source]

Plots the counts histogram for a 1D X-ray spectrum.

axmatplotlib AxesSubplot object

The figure axis on which to plot.

spectrumpyxsis XBinSpectrum object

The binnable 1D spectrum object to plot.

xunitstring (default: ‘keV’)

Defines the unit type to be used on the x-axis. The options are ‘angs’ and ‘keV’.

perbinbool (default: True)

If True, the plot y-axis will show the number of counts per bin. If False, the plot y-axis will show the number of counts per bin-width, depending on the xunit. For example, if xunit=’keV’, then the y-axis units will be counts/keV.

ratebool (default: False)

If True, the plot y-axis will show the number of counts per second. If False, it will show the total number of counts.

plot_bkgbool (default: False)

If True, the background spectrum assigned to the input spectrum will be plotted instead of the primary source spectrum.

subtract_bkgbool (default: True)

If True, the background spectrum assigned to the input spectrum will be subtracted before plotting. If False, no background subtraction will be implemented.

use_backscalebool (default: True)

If True, the background spectrum will be scaled by the pyxsis.XBkgSpectrum.backscale attribute. This attribute generally holds the ratio of the background extraction area to the source extraction area. If False, the raw background spectrum count rate will be used. This is helpful if you just want to view the raw background spectrum.

scale_factorfloat (default: 1.0)

A normalization value to apply to the entire spectrum to be plotted. This option is provided solely for convenience, for example, in comparing spectra to each other.

kwargs are passed to the main histrogram plotting function (ax.step). This can be used to change the color, line widths, line style, and more.

Plot a flux spectrum

pyxsis.plot.plot_unfold(ax, spectrum, xunit='keV', perbin=False, subtract_bkg=True, use_backscale=True, scale_factor=1.0, **kwargs)[source]

Plots the flux histogram for a 1D X-ray spectrum.

axmatplotlib AxesSubplot object

The figure axis on which to plot.

spectrumpyxsis XBinSpectrum object

The binnable 1D spectrum object to plot.

xunitstring (default: ‘keV’)

Defines the unit type to be used on the x-axis. The options are ‘angs’ and ‘keV’.

perbinbool (default: False)

If True, the plot y-axis will show the number of counts per bin. If False, the plot y-axis will show the number of counts per bin-width, depending on the xunit. For example, if xunit=’keV’, then the y-axis units will be counts/keV.

subtract_bkgbool (default: True)

If True, the background spectrum assigned to the input spectrum will be subtracted before plotting. If False, no background subtraction will be implemented.

use_backscalebool (default: True)

If True, the background spectrum will be scaled by the pyxsis.XBkgSpectrum.backscale attribute. This attribute generally holds the ratio of the background extraction area to the source extraction area. If False, the raw background spectrum count rate will be used. This is helpful if you just want to view the raw background spectrum.

scale_factorfloat (default: 1.0)

A normalization value to apply to the entire spectrum to be plotted. This option is provided solely for convenience, for example, in comparing spectra to each other.

kwargs are passed to the main histrogram plotting function (ax.step). This can be used to change the color, line widths, line style, and more.