About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: 9 July 2009

URL: http://cxc.harvard.edu/chips4.1/gallery/multi.sl.html

Gallery: Multiple plots (S-Lang)

Examples


Data, fit, and residuals

This visualization contains two plots arranged vertically, with multiple curves in the first plot. It makes use of the strip_chart command to automatically create multiple plots with "shared" axes (so that a change to the limits of the X axis of one plot is automatically reflected in the other plot).

[ChIPS output]
Postscript version
set_preference("axis.offset.perpendicular","50");

add_window(6.0,3.0,"inches");
strip_chart(2);

variable crv = ChipsCurve;
crv.line.style = "noline";
add_curve("spectrum.fits[data][cols x,y,dylo,dyhi]",crv);
set_curve({"symbol.style","square","symbol.fill",0,"symbol.size",3.0});

variable hist = ChipsHistogram;
hist.line.color = "red";
hist.line.thickness = 2;
add_histogram("spectrum.fits[fit][cols x,y]",hist);

log_scale(Y_AXIS);
set_plot_ylabel("Count s^{-1} keV^{-1}");

current_plot("plot2");

variable resid = read_file("spectrum.fits[residuals]");
variable x = copy_colvals(resid,"x");
variable y = copy_colvals(resid,"y");
variable dylo = copy_colvals(resid,"dylo");
variable dyhi = copy_colvals(resid,"dyhi");
variable dxlo = copy_colvals(resid,"dxlo");
variable dxhi = copy_colvals(resid,"dxhi");
add_curve(x,y,{dylo,dyhi,dxlo,dxhi});
set_curve({"line.style","noline","symbol.style","none"});

add_hline(0.0);

log_scale(X_AXIS);
limits(X_AXIS,0.5,10.0);

set_plot_xlabel("Energy (keV)");
set_plot_ylabel("Residuals (\sigma)"R);

set_xaxis({"offset.perpendicular",40});

adjust_grid_yrelsize(1,2.0);

The set_preference call is used since we know that we need to increase the spacing of the labels for the Y axes of these plots. The offset.perpendicular setting could instead have been changed after the plots were created. A window is explicitly created using add_window so that the dimensions can be changed from the default values; in this case we want a rectangular area that is wider than it is tall (the default window size is square).

Since we want two plots arranged vertically, we can just call strip_chart with a single argument of 2. This creates two equally-sized plots and makes the top plot the current one (i.e. any data we plot such as a curve or histogram will appear in the top plot).

We add a curve and then a histogram to this top plot, using add_curve and add_histogram, and change the attributes of these objects. Before moving to the second plot, the Y axis is changed to a logarithmic scale and a label added to it.

The current_plot call changes to the second plot (the info and info_current commands are useful for finding out what ChIPS objects have been created and what there names are). In order to plot the data - which consists of (x,y) points with errors on both axes - we need to use arrays rather than a filename in the add_curve call. The column values are read in using crates routines; read_file to read in the file and copy_colvals to get the column values. As we only want the errors to be displayed we set the line style of the curve to "noline" and the symbol style to "none".

To represent the y=0 line we add a horizontal line using add_hline; an axis could have been added instead by saying:

add_axis(X_AXIS, 0, 0, 1);
bind_axes("ax1", "ax2");

but the extra information of axes, such as the tick marks and labels, obscure some of the information in this case.

The log_scale and limits calls change the X axes of both plots, since they have been bound together by the strip_chart call.

The relative sizes of the two plots are changed by the adjust_grid_yrelsize call, which makes the first row twice as high as any other row (in this case there is only a single column and two rows).

The output of the info and info_current commands is shown below:

chips> info;
Window [win1]
  Frame [frm1]
    Plot [plot1]   (0.20,0.43)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Histogram [hist1]
    Plot [plot2]   (0.20,0.20)  .. (0.90,0.43)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Line [line1]

chips> info_current;
Window [win1]
  Frame [frm1]
    Plot [plot2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Line [line1]
    Coord Sys [Data]
    Coord Sys ID [plot2_ax1ay1]

Changes in CIAO 4.1


Data, residuals, and contours in one frame

In this example we take the data plotted in the first example and add an extra plot, showing the confidence contours of the fit for two of the parameters. All the plots are placed in the same frame; the layout is created by the low-level col_grid_objects routine which allows you to create a different number of plots in each column. See the following example for a different way of plotting the same data.

[ChIPS output]
Postscript version
set_preference("frame.border.visible","true");
set_preference("axis.offset.perpendicular","50");

add_window(6.0,3.0,"inches");
add_frame();
col_grid_objects([2,1],0.1,0.0,1);
adjust_grid_xrelsize(1,1.2);

add_curve("spectrum.fits[data][cols x,y,dylo,dyhi]");
variable crv = ChipsCurve;
crv.line.style = "noline";
crv.symbol.style = "square";
crv.symbol.fill = 0;
crv.symbol.size = 3.0;
set_curve(crv);

variable hist = ChipsHistogram;
hist.line.color = "red";
hist.line.thickness = 2;
add_histogram("spectrum.fits[fit][cols x,y]",hist);

log_scale(Y_AXIS);
set_plot_ylabel("Count s^{-1} keV^{-1}");
set_xaxis({"ticklabel.visible",0});
set_plot({"bottommargin",0.45});

current_plot("plot2");

add_histogram("spectrum.fits[residuals][cols x,y]");
add_hline(0.0);

set_plot({"topmargin",0.55});

set_plot_xlabel("Energy (keV)");
set_plot_ylabel("Residuals (\sigma)"R);

set_xaxis({"offset.perpendicular",35});

bind_axes("plot1","ax1","plot2","ax1");
log_scale(X_AXIS);

current_plot("plot3");

add_contour("contours.fits",[53.6454,57.5304,63.1794],{"wcs","params"});

set_plot_xlabel("kT_x (keV)");
set_plot_ylabel("Abundance");

set_xaxis({"offset.perpendicular",35});
set_yaxis({"offset.perpendicular",25});

In general the commands used are similar to the first example, although here we have to manually create a frame using add_frame; col_grid_objects is unlike most ChIPS commands in that it will not automatically create the parent objects for you. The frame border has been turned on for comparison with the multi-frame example below.

Once the plots have been created the data can be plotted as before; although note that the residuals are this time plotted as a histogram (without error bars) rather than a curve; the X axis labels of the first plot have been hidden using the ticklabel.visible attribute of the axis; and that the X axes of the data and residual plots have to be manually linked together using the bind_axes call.

The output of the info and info_current commands is shown below:

chips> info;
Window [win1]
  Frame [frm1]
    Plot [plot1]   (0.20,0.45)  .. (0.53,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Histogram [hist1]
    Plot [plot2]   (0.20,0.20)  .. (0.53,0.45)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Histogram [hist1]
      Line [line1]
    Plot [plot3]   (0.63,0.20)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Contour [ctr1]

chips> info_current;
Window [win1]
  Frame [frm1]
    Plot [plot3]
      X Axis [ax1]
      Y Axis [ay1]
      Contour [ctr1]
    Coord Sys [Data]
    Coord Sys ID [plot3_ax1ay1]

Changes in CIAO 4.1

  • The axis ticklabel.visible attribute can now be set using add_axis, set_axis, and in the ChipsAxis structure. It is therefore no longer necessary to use the low-level set_axis_ticklabel_visible() routine to change this attribute.


Data and residuals in one frame, contours in another

This example shows how the data used in the previous example can be plotted using multiple frames: the fit and residuals plots are drawn in one frame and the contour plot added to a second frame.

[ChIPS output]
Postscript version
set_preference("frame.border.visible","true");

add_window(6.0,3.0,"inches");
strip_chart(2);
reposition_frame(0.0,0.0,0.55,1.0);

add_curve("spectrum.fits[data][cols x,y,dylo,dyhi]");
limits(X_AXIS,AUTO,AUTO);
variable crv = ChipsCurve;
crv.line.style = "noline";
crv.symbol.style = "square";
crv.symbol.fill = 0;
crv.symbol.size = 3.0;
set_curve(crv);

variable hist = ChipsHistogram;
hist.line.color = "red";
hist.line.thickness = 2;
add_histogram("spectrum.fits[fit][cols x,y]",hist);

log_scale(Y_AXIS);
set_plot_ylabel("Count s^{-1} keV^{-1}");
set_xaxis({"ticklabel.visible",0});
set_plot({"bottommargin",0.45});

adjust_grid_yrelsize(1,2.0);

current_plot("plot2");

add_histogram("spectrum.fits[residuals][cols x,y]");
add_hline(0.0);
log_scale(X_AXIS);

set_plot_xlabel("Energy (keV)");
set_plot_ylabel("Residuals (\sigma)"R);

set_plot("all",{"leftmargin",0.25});
set_yaxis({"offset.perpendicular",50});

add_frame(0.55,0.0,1.0,1.0);

add_contour("contours.fits",[53.6454,57.5304,63.1794],{"wcs","params"});

set_plot_xlabel("kT_x (keV)");
set_plot_ylabel("Abundance");

set_yaxis({"offset.perpendicular",25});

By using two frames, some operations are simpler in this version, since we can now use strip_chart to plot the data from the file "spectrum.fits"; however we now have to manually position and re-size the frames within the window (using commands like reposition_frame and add_frame).

The output of the info and info_current commands is shown below:

chips> info;
Window [win1]
  Frame [frm1]
    Plot [plot1]   (0.25,0.43)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Curve [crv1]
      Histogram [hist1]
    Plot [plot2]   (0.25,0.20)  .. (0.90,0.43)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Histogram [hist1]
      Line [line1]
  Frame [frm2]
    Plot [plot1]   (0.20,0.20)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Contour [ctr1]

chips> info_current;
Window [win1]
  Frame [frm2]
    Plot [plot1]
      X Axis [ax1]
      Y Axis [ay1]
      Contour [ctr1]
    Coord Sys [Data]
    Coord Sys ID [plot1_ax1ay1]

Changes in CIAO 4.1

  • The axis ticklabel.visible attribute can now be set using add_axis, set_axis, and in the ChipsAxis structure. It is therefore no longer necessary to use the low-level set_axis_ticklabel_visible() routine to change this attribute.

Last modified: 9 July 2009


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