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
 Creating Code for Automation of Graph Creation

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
Neil Stringer Posted - 07/29/2024 : 2:11:19 PM
OriginPro 2024b (64-bit)
10.1.5.132 (Learning Edition)
and Service Release 0:
Operating System: macOS Silicon + Windows Emulator
Hello!
I am trying to write a code to simultaneously:
1. Plot all graphs in a workbook as a line graph with red color (which I have been able to do for one sheet at a time only so far with the code I've written)
2. Fill the area under all those graphs with a 95% transparency red fill
3. Create a textbox in all of those graphs filled with the following phrases: "peak @ [highest peak in graph coordinates], @ [next highest peak in graph coordinates, preferably the next relative max were random fluctiuations and noise eliminated and the general trend only taken,] @ [third peak with the third rel. max]" and "Lines=[information in 'comments' column]".
I have very little experience with LabTalk, and so far have only been able to get step 1 done and only for the first sheet of the workbook. Is there any way such a code could be written? Thank you for your help!


Neil Stringer
6   L A T E S T    R E P L I E S    (Newest First)
Neil Stringer Posted - 07/30/2024 : 4:59:49 PM
Wow, thank you so much! That worked amazingly well. I really appreciate your aid! You've been a tremendous help to me. Enjoy your day.

Neil Stringer
YimingChen Posted - 07/30/2024 : 4:25:37 PM
Please Open the attached project file, save the Graph4 to template PL. Then run the script below:

string strBook = %H; // %H is the active window name.
int numSheets = page.nlayers;
for(int ii = 1; ii <= numSheets; ii++) {	
	plotxy [%(strBook$)]$(ii)!(1,2) plot:=200 ogl:=[<new template:=PL>]; // Update graph
	dataset ds;
	pkFind iy:=1 npts:=10 ocenter_y:=ds ocenter:=<none> oleft:=<none> oright:=<none> ;
	range -wx rx = 1;
	range -wy ry = 1;
	dataset ds_sorted = sort(ds);
	int nn = ds_sorted.GetSize();
	double x1 = rx[list(ds_sorted[nn], ry)];
	double x2 = rx[list(ds_sorted[nn-1], ry)];
	double x3 = rx[list(ds_sorted[nn-2], ry)];
	label -s \v(peak @x=$(x1), @x=$(x2), @x=$(x3));
}


https://my.originlab.com/ftp/forum_and_kbase/Images/BatchPlottingSample.opju

James
Neil Stringer Posted - 07/30/2024 : 2:10:57 PM
Of course! Here is the code I have written so far:
"// Loop through all sheets in the active workbook
int numSheets = page.nlayers;
for(int ii = 1; ii <= numSheets; ii++) {
// Activate the current sheet
page.active = ii; range rX= col(A); range rY= col(B); plotxy (rX, rY) plot:=200 ogl:=[<new template:=PL>]; // Update graph
layer -a; // Ensure the correct layer is active for modifications
}

// Reactivate the first sheet
page.active = 1;"


The parts which currently function to get me a graph in the template I set up are "range rX= col(A); range rY= col(B); plotxy (rX, rY) plot:=200 ogl:=[<new template:=PL>];"


When I say "pull data," i am essentially trying to get the template to autodetect the first, second, and third relative maximums in the graph so that I can label the peaks. Part of the difficulty with that plan is that the data I am using has noise, so a noise peak near the beginning of the graph may be recognized instead of the peak of the actual trend I am searching for; I am unsure if some sort of trendline layer could reduce this difficulty. The second part of data I wish to pull is for the template to autofill the X in "Lines=X" where X is defined as what I have written in the "Comments" cell in column A(X). I would love to be able to place my data in with certain comments and have the information in those comment cells automatically appear in the graph. Let me now if I can clarify further. Thank you so much!


Neil Stringer
YimingChen Posted - 07/30/2024 : 11:55:08 AM
Could you share your LT script here?

By saying "pull the data in brackets in the first post from the template", are you trying to get the worksheet data range? Maybe you can check the page below:
https://www.originlab.com/doc/en/LabTalk/guide/Range-Notation#Option_Switches_-w.2C_-wx.2C_-wy_and_-wzOption_Switche

James

quote:
Originally posted by Neil Stringer

Thank you for the help! With the new method I am now able to complete steps 1 and 2 and manually work on step 3. However, I seem to be getting an "error setting property values" whenever I try to loop the script. Additionally, is there a way to add to the template automation so that it will pull the data in brackets in the first post from the template? Thank you so much for your help!


Neil Stringer

Neil Stringer Posted - 07/29/2024 : 5:09:12 PM
Thank you for the help! With the new method I am now able to complete steps 1 and 2 and manually work on step 3. However, I seem to be getting an "error setting property values" whenever I try to loop the script. Additionally, is there a way to add to the template automation so that it will pull the data in brackets in the first post from the template? Thank you so much for your help!


Neil Stringer
YimingChen Posted - 07/29/2024 : 2:53:18 PM
You can save a graph template first, then use LT script to plot data using the specified template. Check the example 7 of the page below:
https://www.originlab.com/doc/en/X-Function/ref/plotxy

James

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