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/bind.sl.html

Gallery: Sharing an axis between plots (S-Lang)

Examples


Three datasets in separate plots with a common axis

There are a several ways to create a grid of plots; in this example we use the strip_chart command to create three vertically-aligned plots which have a "shared" or "common" X axis (so that changes to the scaling or limits of one X axis is automatically reflected in all three plots). It also highlights some of the different ways to control the appearance of axes; in particular how to select the arrangement of major and minor tick marks.

The data to be plotted is from the aspect solution of a Chandra observation; we wish to show how the RA, Dec, and Roll of the telescope varied with time.

[ChIPS output]
Postscript version
variable pref = ChipsPreferences;
pref.curve.symbol.style = "none";
pref.plot.style = "open";
pref.axis.offset.perpendicular = 70;
pref.axis.ticklabel.offset = 10;
set_preferences(pref);

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

add_curve("aspect.fits[cols time,ra]");

limits(X_AXIS,AUTO,AUTO);

variable ax = ChipsAxis;
ax.majortick.style = "centered";
ax.minortick.style = "centered";
ax.majortick.length = 8;
ax.minortick.length = 4;
set_xaxis(ax);
variable ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 5.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);
set_plot_ylabel("RA");

current_plot("plot2");
add_curve("aspect.fits[cols time,dec]");

ax = ChipsAxis;
ax.majortick.style = "centered";
ax.minortick.style = "centered";
ax.majortick.length = 8;
ax.minortick.length = 4;
set_xaxis(ax);
ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 2.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);
set_plot_ylabel("Dec");

current_plot("plot3");
add_curve("aspect.fits[cols time,roll]");

set_plot_xlabel("Time (s)");
set_plot_ylabel("Roll");
set_xaxis({"tickformat","%.0f","offset.perpendicular",45});
ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 5.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);

Before we create the plot we change several ChIPS preferences: curves are only displayed as lines, plots are drawn using the "open" style - which means that only the bottom and left edges of the plot contain an axis, and the offsets for the axis labels are increased. The set_preferences call applies these settings.

Since the default window size is square, the add_window routine is used to create a rectangular window. We then fill this window with three vertically-arranged plots by calling strip_chart. At this point the output of info and info_current looks like:

chips> info;
Window [win1]
  Frame [frm1]
    Plot [plot1]   (0.15,0.65)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
    Plot [plot2]   (0.15,0.40)  .. (0.90,0.65)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
    Plot [plot3]   (0.15,0.15)  .. (0.90,0.40)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]

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

The top plot, which is current, is used to display the RA versus time data. After creating the curve with add_curve, the X axis limits are changed to match the data range by setting both the minimum and maximum values to AUTO using the limits command; this is necessary since the default axes created by strip_chart cover the range 0 to 1 so without this call the X axis would start at 0 rather than 6.8 x 107. Since all three plots have linked X axes, this range is automatically applied to all the plots.

The tick marks for both axes in this plot are adjusted using the set_xaxis and set_yaxis calls; of note is the change in the mode used to position the major tick marks on the Y axis so that they are spaced at intervals of 0.005 degrees.

The second plot is used to display the variation of the telescope Declination with time and the third plot the roll variation. In all plots similar adjustments are made to tweak the axes.


Three datasets in separated plots

Here we plot the same data as the initial example, this time with a small vertical gap between the plot created by setting the optional third argument of strip_chart to 0.05 (the default is 0).

[ChIPS output]
Postscript version
set_preference("curve.symbol.style","none");
set_preference("axis.offset.perpendicular","70");

add_window(6.0,3.0,"inches");
strip_chart(3,0,5.0e-2);

add_curve("aspect.fits[cols time,ra]");
limits(X_AXIS,AUTO,AUTO);

variable ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 5.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);
set_plot_ylabel("RA");

current_plot("plot2");
add_curve("aspect.fits[cols time,dec]");

ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 2.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);
set_plot_ylabel("Dec");

current_plot("plot3");
add_curve("aspect.fits[cols time,roll]");

set_plot_xlabel("Time (s)");
set_plot_ylabel("Roll");
set_xaxis({"offset.perpendicular",45,"tickformat","%.0f"});
ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 5.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);

Three datasets in separate plots with a hidden X axis

Here we take the arrangement from the first example and hide the X axes of the top two plots to make it appear as if there is a single plot with three different Y axes. The borders of a plot can also be used to display axes, as is shown with the Y axes in the middle plot.

[ChIPS output]
Postscript version
variable pref = ChipsPreferences;
pref.curve.symbol.style = "none";
pref.plot.style = "open";
pref.axis.offset.perpendicular = 30;
pref.plot.leftmargin = 0.15;
pref.plot.rightmargin = 0.15;
set_preferences(pref);

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

% Display the data and then re-set the X axis to display the correct range
add_curve("aspect.fits[cols time,ra]");
limits(X_AXIS,AUTO,AUTO);

add_label(1.05,0.5,"RA",{"coordsys",PLOT_NORM});

hide_axis("ax1");
variable ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 5.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);

current_plot("plot2");
add_curve("aspect.fits[cols time,dec]");

add_label(-0.1,0.5,"Dec",{"coordsys",PLOT_NORM});

% Hide the default X (bottom) and Y (left) axes then display an axis on the right
hide_axis;
display_axis("by2");
variable axis = ChipsAxis;
axis.ticklabel.visible = 1;
axis.majortick.mode = "interval";
axis.majortick.interval = 2.0e-3;
axis.tickformat = "%.3f";
set_axis("by2",axis);

current_plot("plot3");

add_curve("aspect.fits[cols time,roll]");
set_xaxis({"tickformat","%.0f"});
ay = ChipsAxis;
ay.majortick.mode = "interval";
ay.majortick.interval = 5.0e-3;
ay.tickformat = "%.3f";
set_yaxis(ay);

set_plot_xlabel("Time (s)");
add_label(1.05,0.5,"Roll",{"coordsys",PLOT_NORM});

When creating a strip chart, all the common axes - in this case the X axes - are automatically bound together and set to cover the range 0 - 1 (plus whatever the axes padding is set to). When data is added to the first plot - in this case the time and ra columns from aspect.fits - the data range is set to a union of 0 - 1 with the data range (in this case the time column). This results in the X axis covering the approximate range 0 - 7 x 107, so we change the limits to match just the data by saying

limits (X_AXIS, AUTO, AUTO);

In the middle plot we want to hide both the X and Y axes and display a Y axis on the right-hand side. This can be done by making the "by2" border visible and changing its attributes to have the desired tick spacing and format.

Changes in CIAO 4.1

  1. The coordinate system to be used when placing an object can now be declared in the attribute list, using the attribute name "coordsys", whereas previously you had to create a ChipsId object and set its coord_sys field. So

    variable cid = ChipsId;
    cid.coord_sys = PLOT_NORM;
    add_label (cid, 1.05, 0.5, "\Delta \alpha (deg)"R);
    

    can now be written

    add_label (1.05, 0.5, "\Delta \alpha (deg)"R, {"coordsys", PLOT_NORM});
    
  2. 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.


A grid where the plots share axes and the plot sizes are different

The split command is useful when you want to create a grid of plots (i.e. with multiple rows and columns). In this example we use it to create a 2 by 2 arrangement of plots; this is then modified by deleting the last plot and adjusting the relative widths and heights so that the first plot is twice as big as the other two plots.

The main plot is used to show the Right Ascension and Declination of the telescope varied together (the data used is a small subset of the Chandra observation and so does not show the full Lissajous curve you would expect to see). The secondary plots are used to show the temporal variation of the two axes; even though the time axes in these plots have been hidden for display purposes, you can still display data using these axes.

[ChIPS output]
Postscript version
variable pref = ChipsPreferences;
pref.curve.symbol.style = "none";
pref.plot.leftmargin = 0.25;
pref.plot.rightmargin = 0.1;
pref.plot.bottommargin = 0.1;
pref.axis.offset.perpendicular = 10;
set_preferences(pref);

split(2,2);
adjust_grid_xrelsize(1,2.0);
adjust_grid_yrelsize(1,2.0);

add_curve("aspect.fits[cols ra,dec]");

variable ay = ChipsAxis;
ay.majortick.interval = 2.0e-3;
ay.majortick.mode = "interval";
ay.minortick.count = 3;
ay.tickformat = "dec";
set_yaxis(ay);

set_xaxis({"ticklabel.visible",0});
set_axis("bx2",{"x.label","RA"});

current_plot("plot2");
add_curve("aspect.fits[cols time,dec]");

bind_axes("plot1","ay1","plot2","ay1");
set_axis({"ticklabel.visible",0});
set_axis("by2",{"y.label","Dec"});

% Hide both the lower and upper X axes
set_cascading_property("ax1",chips_axis,"visible","0");
set_cascading_property("bx2",chips_axis,"visible","0");

% Add a label above the plot along the X axis
% (we can not add it to the X axis by2 since it is hidden)
add_label(0.5,1.05,"Time",{"coordsys",PLOT_NORM,"halign",0.5,"size",14.0});

current_plot("plot3");
add_curve("aspect.fits[cols ra,time]");

bind_axes("plot1","ax1","plot3","ax1");

set_xaxis({"tickformat","ra"});
reverse_axes(X_AXIS);
variable ax = ChipsAxis;
ax.majortick.interval = 1.0e-2;
ax.majortick.mode = "interval";
ax.minortick.count = 3;
set_xaxis(ax);

% Hide both the left and right Y axes
set_cascading_property("ay1",chips_axis,"visible","0");
set_cascading_property("by2",chips_axis,"visible","0");

% Add a label to the left of the plot along the Y axis
add_label(-0.1,0.5,"Time",{"coordsys",PLOT_NORM,"halign",0.5,"size",14.0,"angle",90.0});

% Remove the un-used plot created by split
delete_plot("plot4");

For full control over the grid - including support for varying number of rows or columns, use one of the the grid_objects, col_grid_objects, or row_grid_objects routines.

Changes in CIAO 4.1

  1. The coordinate system to be used when placing an object can now be declared in the attribute list, using the attribute name "coordsys", whereas previously you had to create a ChipsId object and set its coord_sys field. So

    variable cid = ChipsId;
    cid.coord_sys = PLOT_NORM;
    add_label (cid, 1.05, 0.5, "\Delta \alpha (deg)"R);
    

    can now be written

    add_label (1.05, 0.5, "\Delta \alpha (deg)"R, {"coordsys", PLOT_NORM});
    
  2. In CIAO 4.0, axis labels, when displayed in "RA" format, could occasionally display values such as "17h 16m 60s". In CIAO 4.1 this has been changed to display "17h 17m 00s", as shown above.

  3. 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.