# 6.1.3.5. Plot commands¶

Next to the PGPLOT plotting system of SPEX, the python interface can also be used for plotting. In this section, we provide a list of commands for plotting spectral models, the effective area and spectral data (including residuals).

## 6.1.3.5.1. Plot spectral model¶

The SPEX plot type ‘model’ plots the model spectrum as a function of energy. In PYSPEX there is a function to obtain the same plot using matplotlib:

`Session.``plot_model`(xlog=False, ylog=False, title='SPEX Model Spectrum', show=True)[source]

Plot the spectral model.

Parameters
• xlog (bool) – (Optional) Set the X-axis to be logarithmic.

• ylog (bool) – (Optional) Set the Y-axis to be logarithmic.

• title (str) – (Optional) Set the title of the plot.

• show (bool) – (Optional) Show the plot (True) or return the plot object (False).

Returns

Plot object and optionally the matplotlib plt object.

Return type

pyspex.plot.PlotModel, matplotlib.pyplot

This function plots the model spectrum as a function of energy (keV). The axis can be made logarithmic by setting `xlog=True` and `ylog=True` for the x and y axis, respectively.

Examples:

```>>> s.plot_model()
>>> s.plot_model(xlog=True, ylog=True)
```

## 6.1.3.5.2. Plot data¶

The SPEX data plot type plots the observed spectrum, the folded model and background spectrum. In PYSPEX, this is done with one command called `plot_data`:

`Session.``plot_data`(xlog=False, ylog=False, title='SPEX', show=True)[source]

Plot the observed spectrum with the convolved model for all instruments.

Parameters
• xlog (bool) – (Optional) Set the X-axis to be logarithmic.

• ylog (bool) – (Optional) Set the Y-axis to be logarithmic.

• title (str) – (Optional) Set the title of the plot.

• show (bool) – (Optional) Show the plot (True) or return the plot object (False).

Returns

Plot object and optionally the matplotlib plt object.

Return type

pyspex.plot.PlotData, matplotlib.pyplot

This function plots the observed spectra in black, the convolved model in red, and the background spectrum as a dashed blue line. The axis can be made logarithmic by setting `xlog=True` and `ylog=True` for the x and y axis, respectively.

Examples:

```>>> s.plot_data()
>>> s.plot_data(xlog=True, ylog=True)
```

### 6.1.3.5.2.1. Plot data with residuals¶

It is also possible to attach a subplot with residuals to the main data plot. To do this, one uses the `plot_chi` command:

`Session.``plot_chi`(xlog=False, ylog=False, chi='dchi', title='SPEX', show=True)[source]

Plot the observed spectrum with the convolved model and their residuals for all instruments.

Parameters
• xlog (bool) – (Optional) Set the X-axis to be logarithmic.

• ylog (bool) – (Optional) Set the Y-axis to be logarithmic.

• chi (str) – (Optional) Type of residual, either ‘dchi’ or ‘rel’.

• title (str) – (Optional) Set the title of the plot.

• show (bool) – (Optional) Show the plot (True) or return the plot object (False).

Returns

Plot object and optionally the matplotlib plt object.

Return type

pyspex.plot.PlotData, matplotlib.pyplot

In addition to the xlog and ylog parameter, this function can also set the residual type. Currently, `dchi` and `rel` are implemented.

Examples:

```>>> s.plot_chi()
>>> s.plot_chi(chi='rel')
```

### 6.1.3.5.2.2. Plot data with model components¶

For models with multiple additive components, it is possible in PYSPEX to plot the total model and the contributions from the individual additive components with the `plot_comp` method.

`Session.``plot_comp`(xlog=False, ylog=False, title='SPEX', show=True)[source]

Plot the individual model components.

Parameters
• xlog (bool) – (Optional) Set the X-axis to be logarithmic.

• ylog (bool) – (Optional) Set the Y-axis to be logarithmic.

• title (str) – (Optional) Set the title of the plot.

• show (bool) – (Optional) Show the plot (True) or return the plot object (False).

Returns

Plot object and optionally the matplotlib plt object.

Return type

pyspex.plot.PlotData, matplotlib.pyplot

Examples:

```>>> s.plot_comp()
>>> s.plot_comp(ylog=True, title='Spectral components')
```

## 6.1.3.5.3. Plot effective area¶

The SPEX plot type ‘area’ plots the effective area as a function of energy. In PYSPEX there is a function to obtain the same plot using matplotlib:

`Session.``plot_area`(xlog=False, ylog=False, title='Effective Area', show=True)[source]

Plot the effective area of all instruments.

Parameters
• xlog (bool) – (Optional) Set the X-axis to be logarithmic.

• ylog (bool) – (Optional) Set the Y-axis to be logarithmic.

• title (str) – (Optional) Set the title of the plot.

• show (bool) – (Optional) Show the plot (True) or return the plot object (False).

Returns

Plot object and optionally the matplotlib plt object.

Return type

pyspex.plot.PlotArea, matplotlib.pyplot

This function plots the effective area as a function of energy (keV). The axis can be made logarithmic by setting `xlog=True` and `ylog=True` for the x and y axis, respectively.

Examples:

```>>> s.plot_area()
>>> s.plot_area(xlog=True, ylog=True)
```