Last modified: 12 December 2024

How can I include multiple datasets in the same plot?


Sherpa provides some support for plotting multiple datasets together, as discussed here. It is also possible to add data using the plotting backend, such as with the Matplotlbi examples.

In the following we assume you have two data sets loaded with ids of 1 (i.e. the default) and 2, that you have done the following

sherpa> set_xlog()
sherpa> set_ylog()

and that fits have been made to both data sets.

If you wish to display multiple datasets in the same plot then you have to set the overplot argument to True; for example if you have two datasets with ids of 1 and 2 then:

sherpa> plot_data(alpha=0.6)
sherpa> plot_data(2, alpha=0.6, overplot=True)

will display the two data sets in the same plot, with the second dataset drawn in orange. Note that the plot title is not changed when extra datasets are added.

Overplotting different data sets

[The two data sets are shown on the same graph (of Counts/sec/kev versus Energy (keV)). The two data sets have very-different continuum shapes.]
[Print media version: The two data sets are shown on the same graph (of Counts/sec/kev versus Energy (keV)). The two data sets have very-different continuum shapes.]

Overplotting different data sets

The two data set are drawn partially transparent; the alpha option goes from 0 (transparent) to 1 (fully opaque).

You can overplot data from the same data set; for instance if you want the residuals shown on the same graph as the data you could say

sherpa> plot_fit(ylog=False)
sherpa> plot_resid(overplot=True, marker='s', markersize=3, alpha=0.5)

Overplotting residuals

[The residuals are shown on the same plot as the fit (data and models).]
[Print media version: The residuals are shown on the same plot as the fit (data and models).]

Overplotting residuals

The residuals are drawn with a small square symbol (rather than the default which is a small circular symbol) to help distinguish them from the data.

You can overlay fits, with the choice of colors depending on the plot backend:

sherpa> plot_fit(1, alpha=0.5)
sherpa> plot_fit(2, alpha=0.5, overplot=True)

Overplotting fits

[The data and model from the two fits are drawn on the same graph. Fortunately as the spectral shape is different it is not too hard to separate the two.]
[Print media version: The data and model from the two fits are drawn on the same graph. Fortunately as the spectral shape is different it is not too hard to separate the two.]

Overplotting fits