PlotManager

class xspec.PlotManager(deviceStr)

Xspec plotting class.

PyXspec automatically creates a single object of this class, named Plot.

Methods

  • __call__ (the '()' operator)

  • addCommand

  • addComp

  • backgroundVals

  • contourLevels

  • delCommand

  • iplot

  • labels

  • model

  • nAddComps

  • noID

  • setGroup

  • setID

  • setRebin

  • show

  • x

  • xErr

  • y

  • yErr

  • z

Attributes

  • add

  • area

  • background

  • commands

  • device

  • perHz

  • redshift

  • splashPage

  • xAxis

  • xLog

  • yLog

__call__(*panes)

Display the plot.

Input 1 or more plot command strings.

Examples:

# Single Plots: 
Plot("data")
Plot("model")
Plot("ufspec")

# Multiple Plots (or single plots taking additional arguments):
Plot("data","model","resid")
Plot("data model resid")
Plot("data,model,resid")
Plot("data","model m1")  # Plots data and a model named "m1".

# To repeat a plot using the previously entered arguments, simply do: 
Plot()
__init__(deviceStr)
addCommand(cmd)

Add a plot command [string] to the end of the plot commands list.

addComp(addCompNum=1, plotGroup=1, plotWindow=1)

Return a list of Y-coordinates for a particular add component of a model

The individual add component arrays of a model are generated in 'data' and 'model' plots when Plot.add = True. Add components are numbered from 1 to N where N is the total number of add components from all models in the plot group. (A data plot may have multiple models associated with a spectrum.) See also the Plot.nAddComps() method for obtaining the value N.

This call is valid only if the add component belongs to a model which has multiple add components.

backgroundVals(plotGroup=1, plotWindow=1)

Return a list of background data values for a plot group and plot window

Background value arrays only exist for data plots when the Plot.background flag is set to True.

contourLevels()

Return a list of the values of the drawn levels in a contour plot.

This method should only be called when the most recent Plot() call produces a 2D contour plot. Otherwise this will raise an error.

delCommand(num)

Remove a plot command by (1-based) number [int].

This is intended for removal of single commands. To remove ALL commands, set the Plot.commands attribute to an empty tuple, ie:

>>> Plot.commands = ()
iplot(*panes)

Display the plot and leave it in interactive plotting mode.

This function takes the same arguments and syntax as when displaying plots in the regular mode (through Plot's __call__ method). Examples:

Plot.iplot("data")   # 1-panel data plot
Plot.iplot("data model")    # 2-panel data and model
Plot.iplot()                # Repeats the previous plot.
labels(plotWindow=1)

Get the X, Y, and Title labels for the specified plot window.

The plot window argument is optional and defaults to 1.

Returns a tuple of strings (X_label, Y_label, Title). If any labels are missing the corresponding string will be empty. Special characters (ie. sub/superscripts, Greek, etc.) are produced in TeX format for compatibility with matplotlib.

model(plotGroup=1, plotWindow=1)

Return a list of Y-coordinate model values for a plot group and plot window

nAddComps(plotGroup=1, plotWindow=1)

Return the number of add component plots for a given plot group.

For plots showing the contributions from the individual additive components of a model, this returns the number of add components displayed for a particular plot group in a plot window. This may be helpful for determining the valid range of the addCompNum input argument to Plot.addComps().

This returns 0 if individual add components are not plotted, either because add components are not relevant to the type of plot or because the model(s) do not consist of multiple add components.

noID()

Turn off the plotting of line IDs.

setGroup(groupStr)

Define a range of spectra to be in the same plot group.

Input argument is a string specifying one or more ranges, delimited by commas and/or spaces. Examples:

# Spectra 1-3 in plot group 1, 4-6 in group 2.
Plot.setGroup("1-3  4-6")

# Spectra 1, 2, and 4 are each now in their own group.           
Plot.setGroup("1,2 4")

# All spectra are in a single plot group. 
Plot.setGroup("1-**")

# If input argument is Python's 'None' variable, all
# plot grouping will be removed.  
Plot.setGroup(None)    
setID(temperature=None, emissivity=None, redshift=None)

Switch on plotting of line IDs.

All input arguments are floats and are optional. If they are omitted they will retain their previous values.

  • temperature: Selects the temperature of the APEC line list.

  • emissitivity: Only lines with emissivities above this setting will be displayed.

  • redshift: Line display will be redshifted by this amount.

To turn off plotting of line IDs, use the noID() function.

setRebin(minSig=None, maxBins=None, groupNum=None, errType=None)

Define characteristics used in rebinning the data (for plotting purposes ONLY).

All input arguments are optional. If they are omitted they will retain their previous values.

  • minSig: Bins will be combined until this minimum significance is reached (in units of sigma). [float]

  • maxBins: The maximum number of bins to combine in attempt to reach minSig. [int]

  • groupNum: The plot group number to which this setting applies. If number is negative, it will apply to ALL plot groups. [int]

  • errType: Specifies how to calculate the error bars on the new bins. Valid entries are "quad", "sqrt", "poiss-1","poiss-2", "poiss-3". [string] See the "setplot" description in the XSPEC manual for more information.

show()

Display current plot settings

x(plotGroup=1, plotWindow=1)

Return a list of X-coordinate data values for a plot group and plot window

xErr(plotGroup=1, plotWindow=1)

Return a list of X-coordinate errors for a plot group and plot window

y(plotGroup=1, plotWindow=1)

Return a list of Y-coordinate data values for a plot group and plot window

yErr(plotGroup=1, plotWindow=1)

Return a list of Y-coordinate errors for a plot group and plot window

z()

Return a 2D list of the grid values for a 2D contour plot

The returned format is particularly useful for insertion into matplotlib.pyplot's contour function. If the current plot is not a 2D contour plot, this returns an error.

property add

Turn on/off the display of individual additive components [bool].

property area

Toggle displaying the data divided by the response effective area for each channel [bool].

property background

Toggle displaying the background spectrum (if any) when plotting data [bool].

property commands
Custom plot commands to be appended to Xspec-generated

commands.

Get: Returns a tuple of the currently entered command strings.

Set: Replaces all commands with the new tuple of strings.

To remove ALL plot commands, set to an empty tuple, ie:
>>> Plot.commands = ()

For inserting and deleting individual commands, use addCommand and delCommand functions.

property device

The plotting device name [string].

property perHz

Toggle displaying Y-axis units per Hz when using wavelength units for X-axis [bool].

property redshift

Apply a redshift to the X-axis energy or wavelength values [float].

This will multiply X-axis energies by a factor of (1+z) to allow for viewing in the source frame. Y-axis values will be equally affected in plots which are normalized by energy or wavelength. Note that this is not connected in any way to redshift parameters in the model (or the setplot id redshift parameter) and should only be used for illustrative purposes.

property splashPage

When set to False, the usual XSPEC version and build data information will not be printed to the screen when the first plot window is initially opened [bool].

property xAxis

X-Axis Units [string].

Valid options are: "channel", (energies) "keV", "MeV", "GeV", "Hz", (wavelengths) "angstrom", "cm", "micron", nm"

These are case-insensitive and may be abbreviated.

This setting also affects the ignore/notice range interpretation.

property xLog

Set the x-axis to logarithmic or linear for energy or wavelength plots [bool].

xLog has no effect on plots in channel space. xLog and yLog will not work for model-related plots (eg. model, ufspec, and their variants) as their axes are always set to log scale.

property yLog

See xLog.