2.9.3 Managing Layers
Creating a panel plotManage Layer
The newpanel X-Function creates a new graph with an n x m layerLayer, Adding arrangement.
Creating a 6 panel graph
The following example will create a new graph window with 6 layers, arranged as 2 columns and 3 rows. This function can be run independent of what window is active.
newpanel col:=2 row:=3;
Remember that when using X-Functions you do not always need to use the variable name when assigning values; however, being explicit with col:= and row:= may make your code more readable. To save yourself some typing, in place of the code above, you can use the following:
newpanel 2 3;
Creating and plotting into a 6 panel graph
The following example will import some data into a new workbook, create a new graph window with 6 layers, arranged as 2 columns and 3 rows, and loop through each layer (panel), plotting the imported data.
// Create a new workbook
// Import a file
path$ = system.path.program$ + "Samples\Graphing\";
fname$ = path$ + "waterfall2.dat";
// Save the workbook name as newpanel will change %H
// Create a 2*3 panel
newpanel 2 3;
// Plot the data
for (ii=2; ii<8; ii++)
plotxy iy:=[bkname$]1!wcol(ii) plot:=200 ogl:=$(ii-1);
Adding Layers to a Graph WindowAdd Layer
The layadd X-Function creates/adds a new layerLayer, Add layer to a graph window. This function is the equivalent of the Insert: New Layer(Axes) menu.
Programmatically adding a layer to a graph is not common. It is recommended to create a graph template ahead of time and then use the plotxy X-Function to plot into your graph template.
The following example will add an independent right Y axis scale. A new layer is added, displaying only the right Y axis. It is linked in dimension and the X axis is linked to the current active layer at the time the layer is added. The new added layer becomes the active layer.
Arranging the layersArrange LayerLayer Arrangement
The layarrange X-Function is used to arrange the layers on the graph page.
Programmatically arranging layers on a graph is not common. It is recommended to create a graph template ahead of time and then use the plotxy X-Function to plot into your graph template.
The following example will arrange the existing layers on the active graph into two rows by three columns. If the active graph does not already have 6 layers, it will not add any new layers. It arranges only the layers that exist.
layarrange row:=2 col:=3;
Moving a layerMove layerLayer, Move
The laysetpos X-Function is used to set the position of one or more layers in the graph, relative to the page.
The following example will left align all layers in the active graph window, setting their position to be 15% from the left-hand side of the page.
laysetpos layer:="1:0" left:=15;
Swap two layersSwap LayersLayer, Swap
The layswap X-Function is used to swap the location/position of two graph layers. You can reference the layers by name or number.
The following example will swap the position on the page of layers indexed 1 and 2.
layswap igl1:=1 igl2:=2;
The following example will swap the position on the page of layers named Layer1 and Layer2.
layswap igl1:=Layer1 igl2:=Layer2;
Layers can be renamed from both the Layer Management tool as well as the Plot Details dialog. In the Layer Management tool, you can double-click on the Name in the Layer Selection list, to rename. In the left-hand navigation panel of the Plot Details dialog, you can slow double-click a layer name to rename.
To rename from LabTalk, use layern.name$ where n is the layer index. For example, to rename layer index 1 to Power, use the following: layer1.name$="Power";
Aligning layersAlign LayerLayer Alignment
The layalign X-Function is used to align one or more layers relative to a source/reference layer.
The following example will bottom align layer 2 with layer 1 in the active graph window.
layalign igl:=1 destlayer:=2 direction:=bottom;
The following example will left align layers 2, 3 and 4 with layer 1 in the active graph window.
layalign igl:=1 destlayer:=2:4 direction:=left;
The following example will left align all layers in Graph3 with respect to layer 1. The 2:0 notation means for all layers, starting with layer 2 and ending with the last layer in the graph.
layalign igp:=graph3 igl:=1 destlayer:=2:0 direction:=left;
Linking LayersLink LayersLayer, Linking
The laylink X-Function is used for linking layers to one another. It is used to link axes scales as well as layer area/position.
The following example will link all X axes in all layers in the active graph to the X axis of layer 1. The Units will be set to % of Linked Layer.
laylink igl:=1 destlayers:=2:0 XAxis:=1;
Setting Layer Unit
The laysetunit X-Function is used to set the unit for the layer area of one or more layers.