The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Adding graph layers (and rounding down!)

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
jdf726 Posted - 06/21/2017 : 1:53:26 PM
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

I was writing a script to make a formatted n*m array of contour plots.
The script is meant to
1) Iterate first over matrix sheets in a folder (to collect their names into a string array)
2) Go to a specific graph (whichever was graphy active when you started the script)
3) Loop over graph layers, replace the existing data with each new matrix data from the string array list.
4) For each layer, set the coordinates, dimensions and many axis settings

I got it to work, but I have two irritations.

First, when looping over the 9 layers (to make a 3 x 3 grid of plots) I wanted to convert the layer loop counter i into row/column coordinates required to position each plot on a grid.
I found that c = mod((i-1),3), gives the 0,1,2,0,1,2... for the column, but when I wanted to do something like "floor(i/3)" I found I couldn't round toward zero. nint() and round() both go to the nearest integer right?
Is there a rounding DOWN function? I did it in the end (see below) but by using 'mod' to work back to 'floor'. Am I being dense - is there an integer division function I missed?

Secondly, I actually prepared my graph with nine layers by hand, but I didn't really want to. How do I create a graph page in the first place, with layers to it, ready for them to be operated on?
I got as far as win -t plot TEMPLATENAME Test, which makes me a graph window with as many layers as the template - can I add layers on the fly? How/when does a layer get created?

Anyways, this works ~ok, but if I knew how to start from scratch I could probably avoid some more messing about (and I could get the labview connection to run this and make the whole graph for me!).


jdf


StringArray aa; //Define buffer for matrix names
doc -ef LB{aa.Add(%H);} //Loop over books in folder to find names
for (i=1;i<=aa.getsize();i++) // Loop over matrix names/layers
{
b$= aa.getat(i)$; //get matrix name
h = 3; //number of rows in output
w = 3; //number of cols in output
dh = 3; //spacing
dw = 3; //spacing
ww = 2.6; //width
hh = 2.6; //height
ox = 3; //start coordinate offset
oy = 9; //strat coordinate
r = 0; //initialise
c = 0; //init.
layer -o i { //loop over layers
c = mod(i-1,h); //work out column
r = ((i-1)-mod(i-1,w))/w; //work out row
cc = ox+(c)*dh; //layer origin
rr = oy+(r)*dw; //layer origin
layer ww hh cc rr; //set layer width,posn
layer -c; //count data in layer
layer -e %Z; //magically delete data
layer -i %(b$); //insert new data
label -xb "X"; //label col
label -yb "Y"; //label row
Rescale; //rescale axis
layer.x2.ticks = 0; //turn off ticks
layer.y2.ticks = 0; //turn off ticks
layer.x.from = -89; //limits
layer.x.to = +89; //limits
layer.x.inc = 60; //tick interval
layer.x.minorTicks = 5; //ticks
layer.y.from = -8; //limits
layer.y.to = 8; //limits
layer.y.inc = 5; //interval
layer.y.minorTicks = 4; //#ticks
layer.cmap.zmin=-0.2; //limits
layer.cmap.zmax=1.6; //limits
layer.cmap.SetLevels(); //update leve;s
layer.cmap.updateScale(); //update
layer.cmap.palette$ = Temperature.Pal;//palette
};
}
4   L A T E S T    R E P L I E S    (Newest First)
jdf726 Posted - 06/22/2017 : 08:45:42 AM
Yay!

It all works first time with some delays (this is a bit rubbish really - I spent ages thinking I had the wrong syntax, but it worked when I tried it separately!)

Here is the working script for the record. I have been meaning to work out how to do this for ages!


jdf




StringArray aa; //Define buffer for matrix names
doc -ef LB{
if (Search("%H","B1")>0)
{
mdim y1:=-12.2 y2:=12.2;
aa.Add(%H);
%H=;}
}
win -t plot Test2;
for (i=1;i<=aa.getsize();i++) // Loop over matrix names/layers
{
i=;
b$= aa.getat(i)$; //get matrix name
h = 3; //number of rows
w = 3; //number of cols
dh = 3; //spacing
dw = 3; //spacing
ww = 2.6; //widtyh
hh = 2.6; //height
ox = 3; //start coordinate offset
oy = 9; //strat coordinate
r = 0; //initialise
c = 0; //init.
if (i>1) layer -n;
layer -u 3;
b$=;
layer -o i { //loop over layers
layer.factor = 1;
i=;
c = mod(i-1,h); //work out column
r = ((i-1)-mod(i-1,w))/w; //work out row
cc = ox+(c)*dh; //layer origin
rr = oy+(r)*dw; //layer origin
layer ww hh cc rr; //set layer width,posn
layer -c; //count data in layer
layer -e %Z; //magically delete data
layer -i226 %(b$); //insert new data
label -xb ""; //label col
label -yb ""; //label row
Rescale; //rescale axis
sec -p 0.1;
layer.x.showLabels = 0;
layer.y.showLabels = 0;
sec -p 0.1;
layer.x2.ticks = 0; //turn off ticks
layer.y2.ticks = 0; //turn off ticks
layer.x.from = -89; //limits
layer.x.to = +89; //limits
layer.x.inc = 60; //tick interval
layer.x.minorTicks = 5; //ticks
layer.y.from = -8; //limits
layer.y.to = 8; //limits
layer.y.inc = 5; //interval
layer.y.minorTicks = 4; //#ticks
layer.cmap.numColors = 100;
layer.cmap.inc = 0.01;
layer.cmap.showLines(3);
layer.cmap.zmin=-0.2; //limits
layer.cmap.zmax=1.6; //limits
layer.cmap.SetLevels(); //update leve;s
layer.cmap.updateScale(); //update
layer.cmap.palette$ = Temperature.Pal;//palette
layer.x2.showAxes = 3;
layer.y2.showAxes = 3;
if (r==h-1) layer.x.showLabels = 1;
if (c==0) layer.y.showLabels = 1;
layer -b a 1;
label -r legend;
};
}
speedmode index:=5 sm:=0;
cpyang Posted - 06/22/2017 : 06:58:15 AM
quote:
Originally posted by jdf726

Is there some 'processing time' during which new layer instructions cannot be set?



There are situations on setting the graph properties that 'processing time' might be an issue, and if you suspect this might be a problem, you can insert waiting code
sec -p 0.1
to make sure.


CP
jdf726 Posted - 06/22/2017 : 04:45:36 AM
Ok, here I am replying to my own topic again, but I am getting closer to the answer, and controlling ALL of the graph layer properties is quite useful, even if this could be solved if I had control over the template used to create the layer...

I can now create the page, generate N layers, arrange then in an nxm grid, fill them with the data I want, and set most of the things I want to control, including display units, scaling, speed mode, label visibility and whether the data is clipped to the frame.

I found that some of the layer settings wouldn't 'take' in the loop, but they would if I ran another identical loop (see at the end - I have to run this bit AFTER the part has finished).

Is there some 'processing time' during which new layer instructions cannot be set?


jdf





StringArray aa; //Define buffer for matrix names
doc -ef LB{aa.Add(%H);} //Loop over books to find names
win -t plot Test2;
for (i=1;i<=aa.getsize();i++) // Loop over matrix names/layers
{
b$= aa.getat(i)$; //get matrix name
h = 3; //number of rows
w = 3; //number of cols
dh = 3; //spacing
dw = 3; //spacing
ww = 2.6; //widtyh
hh = 2.6; //height
ox = 3; //start coordinate offset
oy = 9; //strat coordinate
r = 0; //initialise
c = 0; //init.
if (i>1) layer -n;
layer -u 3;
b$=;
layer -o i { //loop over layers
layer.factor = 1;
i=;
c = mod(i-1,h); //work out column
r = ((i-1)-mod(i-1,w))/w; //work out row
cc = ox+(c)*dh; //layer origin
rr = oy+(r)*dw; //layer origin
layer ww hh cc rr; //set layer width,posn
layer -c; //count data in layer
layer -e %Z; //magically delete data
layer -i226 %(b$); //insert new data
label -xb ""; //label col
label -yb ""; //label row
Rescale; //rescale axis

layer.x.showLabels = 0;
layer.y.showLabels = 0;
//if (r==0) layer.x.showLabels = 1;
//if (c==0) layer.y.showLabels = 1;
layer.x2.ticks = 0; //turn off ticks
layer.y2.ticks = 0; //turn off ticks
layer.x.from = -89; //limits
layer.x.to = +89; //limits
layer.x.inc = 60; //tick interval
layer.x.minorTicks = 5; //ticks
layer.y.from = -8; //limits
layer.y.to = 8; //limits
layer.y.inc = 5; //interval
layer.y.minorTicks = 4; //#ticks
layer.cmap.numColors = 100;
layer.cmap.inc = 0.01;
layer.cmap.showLines(3);
layer.cmap.zmin=-0.2; //limits
layer.cmap.zmax=1.6; //limits
layer.cmap.SetLevels(); //update leve;s
layer.cmap.updateScale(); //update
layer.cmap.palette$ = Temperature.Pal;//palette
layer.x2.showAxes = 3;
layer.y2.showAxes = 3;
layer -b a 1;
};
};
speedmode index:=5 sm:=0; //speed mode off in all layers

for (i=1;i<=9;i++) //loop over layers again to set things that don't work in the other loop
{
layer -o i {
c = mod(i-1,h); //work out column
r = ((i-1)-mod(i-1,w))/w; //work out row
layer.x2.showAxes = 3;
layer.y2.showAxes = 3;
layer.x.showLabels = 0; //hide labels on inner plots
layer.y.showLabels = 0;
if (r==h-1) layer.x.showLabels = 1; //show them on bottom and left edges.
if (c==0) layer.y.showLabels = 1;
}
};
jdf726 Posted - 06/21/2017 : 2:28:51 PM
I discovered the "layer -n;" and "layer -u 3;" commands! to create new layers and sets the units to cm.
But Speed mode is on all 9 plots! (and there is no template, so the contour settings are all wrong...

I suspect that if I create the layer with the correct templete that would fix things...

This is the script now....


StringArray aa; //Define buffer for matrix names
doc -ef LB{aa.Add(%H);} //Loop over books to find names
win -t plot Test2; //NEW: CREATE NEW GRAPH
for (i=1;i<=aa.getsize();i++) // Loop over matrix names/layers
{
b$= aa.getat(i)$; //get matrix name
h = 3; //number of rows
w = 3; //number of cols
dh = 3; //spacing
dw = 3; //spacing
ww = 2.6; //widtyh
hh = 2.6; //height
ox = 3; //start coordinate offset
oy = 9; //strat coordinate
r = 0; //initialise
c = 0; //init.
layer -n; //NEW: ADD LAYERS
layer -u 3; //NEW: CHANGE UNITS
layer -o i { //loop over layers
c = mod(i-1,h); //work out column
r = ((i-1)-mod(i-1,w))/w; //work out row
cc = ox+(c)*dh; //layer origin
rr = oy+(r)*dw; //layer origin
layer ww hh cc rr; //set layer width,posn
layer -c; //count data in layer
layer -e %Z; //magically delete data
layer -i %(b$); //insert new data
label -xb "X"; //label col
label -yb "Y"; //label row
Rescale; //rescale axis
layer.x2.ticks = 0; //turn off ticks
layer.y2.ticks = 0; //turn off ticks
layer.x.from = -89; //limits
layer.x.to = +89; //limits
layer.x.inc = 60; //tick interval
layer.x.minorTicks = 5; //ticks
layer.y.from = -8; //limits
layer.y.to = 8; //limits
layer.y.inc = 5; //interval
layer.y.minorTicks = 4; //#ticks
layer.cmap.zmin=-0.2; //limits
layer.cmap.zmax=1.6; //limits
layer.cmap.SetLevels(); //update leve;s
layer.cmap.updateScale(); //update
layer.cmap.palette$ = Temperature.Pal;//palette
};
}

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000