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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Creating a graph with a grouped lines
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jdf726

78 Posts

Posted - 02/07/2018 :  07:20:16 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2016 Pro
Operating System: Win 7

I am trying to write a labtalk script that plots three different names columns (lets say "On", "Off" and "On-Off") in the same plot, but the data is spread over many workbooks (essentially repeats of the experiments). When I do this by hand, I can neatly use the 'average multiple curves' feature, which uses the fact that I can click a group of plots (all the "On" sweeps, say). When you do this manually it works out nicely, but I am having difficulty automating it.

I have written a function like this (see below) that finds the right books first using a name fragment within a folder, then repeatedly calls 'plotxy' within a loop using these book names as part of a range string.

The trouble is, all of the grouping information is missing, which means that the colour has to be set manually (as below) and I cannot easily use the grouping to assist the average multiple curve data selection.

How do you add a curve to a 'group' so that their line settings can be set using 'group' features?


J.



stringarray ab;
int i=0;
doc -ef W {
if (search(page.longname$,"_Scan")>0)
{
ab.Add(page.longname$);
ab.GetAt(i)$=;
i++;
}
}

int nn = ab.GetSize();
for (i=1;i<nn; i++)
{
ab.GetAt(i)$=;
range rA = ["%(ab.GetAt(i)$)"]Integrated Power!"<Xr On>";
range rB = ["%(ab.GetAt(i)$)"]Integrated Power!"<Xr Off>";
range rC = ["%(ab.GetAt(i)$)"]Integrated Power!"<Xr On - Off>";
rA.nrows=;
plotxy iy:=rA plot:=201 ogl:=[Xr]1! color:=1;
plotxy iy:=rB plot:=201 ogl:=[Xr]1! color:=2;
plotxy iy:=rC plot:=201 ogl:=[Xr]1! color:=3;
}

jdf726

78 Posts

Posted - 02/07/2018 :  4:52:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Actually, perhaps it is not so clear that it is easier to trigger "Average multiple curves" using plot 'groups'...

Certainly for data in the same plot you can click to select the data and then when you trigger the "avecurves" dialog the data ranges are already filled in, but when I tried to select one of three grouped data sets it went wrong (I had some data from another group in my average.)

This made me consider whether it is better to construct the range variables for averaging curves myself programmatically and call avecurves directly.

This would not solve the 'grouping for the purposes of plotting features' (e.g. stack, colour sequences etc.) but would solve the 'selecting which data to average' problem.

THe range variable would be working overtime, as it would have to specify all the X and Y ranges like this

avecurves iy:=(["Booklongname1"]"Sheetname"!("X Column name ","Y column name"),["Booklongname2"]"Sheetname"!("X Column name ","Y column name"),
["Booklongname3"]"Sheetname"!("X Column name ","Y column name"))...;

I guess I would start with an empty string and then build it up bit by bit as I found the names of all the relevant workbooks.
Go to Top of Page

yuki_wu

896 Posts

Posted - 02/08/2018 :  02:10:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

To group the plots, try this command:
layer -g
https://www.originlab.com/doc/LabTalk/ref/Layer-cmd#-g.3B_group_all_datasets_in_the_active_layer

I think you can plot On, Off and On-Off in 3 layers respectively, so that you can calculate the average curve layer by layer.

Regards,
Yuki
OriginLab
Go to Top of Page

jdf726

78 Posts

Posted - 02/08/2018 :  05:36:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This pretty much works I think.

I had to capture the page name that I got got$ (different to what I asked for ask$).
I also had to set which layer the grouping was applied to.
The color command is redundant.

Apart from the fact that I should be doing a loop over the column names/layers, is this 'best practice'?
(I noticed that there is a comment in the manual saying that layer -i is the standard way to insert data, and I have done this with matrices, but never XY data).

J.




stringarray ab;
int i=1;
doc -ef W {
if (search(page.longname$,"_Scan")>0)
{
ab.Add(page.longname$);
ab.GetAt(i)$=;
i++;
}
}
ask$ = "Xraa";
newpanel col:=1 row:=3 name:=ask$;
got$ = page.longname$;
int nn = ab.GetSize();
for (i=1;i<=nn; i++)
{
ab.GetAt(i)$=;
range rA = ["%(ab.GetAt(i)$)"]Integrated Power!"<Xr On>";
rA.nrows=;
plotxy iy:=rA plot:=201 ogl:=[got$]1! color:=1;
layer -o 1 {layer -g;}
}
for (i=1;i<=nn; i++)
{
ab.GetAt(i)$=;
range rA = ["%(ab.GetAt(i)$)"]Integrated Power!"<Xr Off>";
rA.nrows=;
plotxy iy:=rA plot:=201 ogl:=[got$]2! color:=1;
layer -o 2 {layer -g;}
}
for (i=1;i<=nn; i++)
{
ab.GetAt(i)$=;
range rA = ["%(ab.GetAt(i)$)"]Integrated Power!"<Xr On - Off>";
rA.nrows=;
plotxy iy:=rA plot:=201 ogl:=[got$]3! color:=1;
layer -o 3 {layer -g;}
}
Go to Top of Page

jdf726

78 Posts

Posted - 02/08/2018 :  08:31:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Actually Yuki, it would be great if you could explain the syntax required to construct the "XYrange" notation that constitutes the input for avecurves, because while I am looping over the workbooks I might as well build this up in a string, this makes it somewhat divorced from plotting the graph at all. I googled XYrange, but I found mostly a technical explanation of the originc class, not the string format required for an X-function input.

I had two other shorts comments/questions/observations

* The grouping technique you suggested works well by layer, but if I wanted to have three groups in one plot (the code below generates three panels).

* In the last 24 hours I have felt like an idiot twice over, because I have found myself writing some (bad) code to replicate functionality that already existed...
First, to concatenate data (it turns out that 'average multiple curves' can also do something like this) and second, to create arrays of empty graph panels (newpanel does this).
Go to Top of Page

yuki_wu

896 Posts

Posted - 02/24/2018 :  03:45:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

We have a page that is talking about X-Funtion input and output, please take a look:
https://www.originlab.com/doc/LabTalk/guide/XF-Input-and-Output

For example, I have 5 columns in [Book1]Sheet1, then I would like to calculate the average curve of col(B) & col(C), col(D) & col(E).
int nLayerIndex = 1;
for(ii = 2; ii <= 5; ii++)
{
	if(ii > 2 && mod(ii,2) == 0)
		nLayerIndex++;
	plotxy iy:=[Book1]1!(1,$(ii)) o:=[Graph1]$(nLayerIndex)!;
}

doc -e LW
{
	layer -g;
	avecurves method:=ave;
}

After running the script, I will have a one-panel graph and two average curves.

Regards,
Yuki
OriginLab
Go to Top of Page

jdf726

78 Posts

Posted - 03/08/2018 :  12:17:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I got this to work in the end by plotting three different panels and calculating the average in each panel.

When I calculate the average I am essentially using the graph as 'holder' of the data to which I can point the averagexy iy:= parameter.

averagexy -r 0 iy:=["%(G1G$)"]$(ss)!(1:$(nn))

Here "G1G$" is the long name of the graph, ss is the index of the layer and nn is the number of data sets plotted in that layer.

This works in that the graphs simplifies the notation to capture which data set I would like to average but is a slight headache in that the data are visually separated (they are same quantity, but with the stimulus on and off). I guess I can always plot a second graph 'for show'.

I suspect that my question is a really basic one that I have just missed somewhere along the way, which is how you specify multiple XY ranges for iy, which I would have to do programmatically in a loop.

The range string could get pretty ugly (and long!), but would make it possible for me to formulate iy from the range notation of all the data columns in all the different books.

Should it look something like iy:= =((x,y),(x,y)) where each x would have the form ["Book1Longname"]"IntegratedPower"!"<X_r>"
each y would be ["Book1Longname"]"IntegratedPower"!"Scan Index" and the things that would change is the book name?
(the example uses range notation with column numbers, which looks so much simpler!)


J


PS: The comment box for avecurves is populated brings along the name of the "column", which makes sense if you are averaging over names columns in the same of different book, but I am averaging over columns that have the same name, but from different books. The fitting routines have neat ways to identify datasets in the summary - this might be useful in avecurves.
Go to Top of Page

yuki_wu

896 Posts

Posted - 03/08/2018 :  10:05:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi J,

I suppose you still feel confused about how to specify the XY Range, right? For the active worksheet, you could only specify the XY data pairs by:

(col(XIndex), col(YIndex) or col(XName), col(YName)

Even only by:
col(YIndex) or col(Yname)

For the specific worksheet which is not active, you should add [BookName]SheetName!.

You could take a look at the examples of plotxy X-Function. I think you could take inspiration from this page:
https://www.originlab.com/doc/X-Function/ref/plotxy

Hope it can be some helps.

Regards,
Yuki
OriginLab
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000