2.9.2 Formatting Graphs

Graph Window

A graph window is comprised of a visual page, with an associated Page (Object). Each graph page contains at least one visual layer, with an associated layer object. The graph layer contains a set of X Y axes with associated layer.x and layer.y objects, which are sub-objects of the layer object.

When you have a range variable mapped to a graph page or graph layer, you can use that variable name in place of the word page or layer.

Page Properties

The page object is used to access and modify properties of the active graph window. To output a list of all properties of this object:


The list will contain both numeric and text properties. When setting a text (string) property value, the $ follows the property name.

To read the Short name of the active window:


To read the Long name of the active window:

page.longname$="This name can contain spaces";

You can also access Graph properties or attributes using a range variable instead of the page object. The advantage is that using a range variable works whether or not the desired graph is active.

The example below sets the active graph layer to layer 2, using a range variable to point to the desired graph by name. Once declared, the range variable can be used in place of page:

//Create a Range variable that points to your graph
range rGraph = [Graph3];
//The range now has properties of the page object

Layer Properties

The layer object is used to access and modify properties of the graph layer.

To set the graph layer dimensions:

//Set the layer area units to cm
//Set the Width
//Set the Height 

Fill the Layer Background Color

The laycolor X-Function is used to fill the layer background color. The value you pass to the function for color, corresponds to Origin's color list as seen in the Plot Details dialog (1=black, 2=red, 3=green, etc).

To fill the background color of layer 1 as green:

laycolor layer:=1 color:=3;

Set Speed Mode Properties

The speedmode X-Function is used to set layer speed mode properties.

Update the Legend

The legendupdate X-Function is used to update or reconstruct the graph legend on the page/layer.

Axis Properties

The layer.x and layer.y sub-object of the layer object is used to modify properties of the axes.

To modify the X scale of the active layer:

//Set the scale to Log10
layer.x.type = 2;
//Set the start value
layer.x.from = .001;
//Set the end value
layer.x.to = 1000;
//Set the increment value
layer.x.inc = 2;

If you wish to work with the Y scale, then simply change the x in the above script to a y. If you wish to work with a layer that is not active, you can specify the layer index, layerN.x.from. Example: layer3.y.from = 0;

The Axis command can also be used to access the settings in the Axis dialog.

To change the X Axis Tick Labels to use the values from column C, given a plot of col(B) vs. col(A) with text in col(C), from Sheet1 of Book1:

range aa = [Book1]Sheet1!col(C);
axis -ps X T aa;

Data Plot Properties

The Set (Command) is used to change the attributes of a data plot. The following example shows how the Set command works by changing the properties of the same dataplot several times. In the script, we use sec command to pause one second before changing plot styles.

// Make up some data
col(a) = {1:5};
col(b) = col(a);
// Create a scatter plot
plotxy col(b);

// Set symbol size
// %C is the active dataset
sec -p 1;
set %C -z 20;
// Set symbol shape
sec -p 1;
set %C -k 3;
// Set symbol color
sec -p 1;
set %C -c color(blue);
// Connect the symbols
sec -p 1;
set %C -l 1;
// Change plot line color
sec -p 1;
set %C -cl color(red);
// Set line width to 4 points
sec -p 1;
set %C -w 2000;
// Change solid line to dash
sec -p 1;
set %C -d 1;

Here is another example which plots into a template, DoubleY, with two layers, and then sets dataplot style for the dataplot in the second layer:

// Importing data
string fn$=system.path.program$ + "Samples\Curve Fitting\Enzyme.dat"; 
impasc fname:=fn$;
//declare active worksheet range
range rr = !;
//plot into a template
plotxy iy:=(1,2) plot:=200 ogl:=[<new template:=DoubleY>];
//plot into second layer of active graph, which is graph created from line above
plotxy iy:=%(rr)(1,3) plot:=200 ogl:=2!;
//declare range for first dataplot in layer 2
range r2 = 2!1;
//set line to dash
set r2 -d 1;

Legend and Label

Formatting the Legend and Label are discussed on Creating and Accessing Graphical Objects.