Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: 13 March 2017

How can I include multiple datasets in the same plot?


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> get_data_plot_prefs()["xlog"] = True
sherpa> get_data_plot_prefs()["ylog"] = True

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()
sherpa> plot_data(2, overplot=True)
sherpa> set_curve(["*.color", "orange"])

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.

[The two data sets are shown in the same plot]

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()
sherpa> plot_resid(overplot=True)
sherpa> lin_scale(Y_AXIS)
sherpa> set_curve(["*.color", "orange", "symbol.fill", True])
sherpa> add_label(1, 0.012, "Source")
sherpa> add_label(1, 0.011, "Residuals", ["color", "orange"])
sherpa> set_label("all", ["size", 16, "halign", 0.5])
sherpa> limits(Y_AXIS, AUTO, AUTO)
[The plot contains the data, best fit model, and residuals]

You can overlay fits, but this requires some extra work to identify the different components: for example

sherpa> plot_fit()
sherpa> plot_fit(2, overplot=True)
sherpa> info()

Window [win1]
  Frame [frm25]
    Plot [plot1]   (0.15,0.15)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      Curve [crv1]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv2]
      Curve [crv3]
      Curve [crv4]

sherpa> set_curve("crv3", ["symbol.fill", True, "symbol.style", "square", "*.color", "green"])
sherpa> set_curve("crv4", ["*.color", "blue"])

where we have used ChIPS commands to identify the different plot components and change their values (you can also use the ChIPS GUI to easily modify the Sherpa plots).

[The plot contains the data and best-fit models for the two data sets]

You can even combine data with different axes; for example in the following we add a second Y axis to the top plot to show how the ARF varies with energy:

sherpa> plot_fit_delchi(2)
sherpa> info()

Window [win1]
  Frame [frm27]
    Plot [plot1]   (0.15,0.40)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Curve [crv2]
    Plot [plot2]   (0.15,0.15)  .. (0.90,0.40)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Line [line1]

sherpa> current_plot("plot1")
sherpa> add_axis(Y_AXIS, 1, 0, 1)
sherpa> plot_arf(2, overplot=True)
sherpa> log_scale(Y_AXIS)
sherpa> set_plot_ylabel("ARF (cm^2)")
sherpa> info()

Window [win1]
  Frame [frm27]
    Plot [plot1]   (0.15,0.40)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Curve [crv2]
      Y Axis [ay2]
      Histogram [hist1]
    Plot [plot2]   (0.15,0.15)  .. (0.90,0.40)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Line [line1]

sherpa> set_histogram(["*.color", "orange"])
sherpa> limits(X_AXIS, 0.4, 8)
sherpa> limits(Y_AXIS, 30, 1000)
[The top plot contains data, best-fit model (left Y axis) and ARF (right Y axis); the bottom plot shows the residuals]


Last modified: 13 March 2017
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.