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
 Forum for Python
 How to add text in Origin graph
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cts18488

United Kingdom
83 Posts

Posted - 06/27/2022 :  09:24:04 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2021b and Service Release (Select Help-->About Origin):
Operating System: Windows 10 Enterprise

Hi,

I want to add a text in an Origin graph in a specific place (see picture attached). However, the text will be different from graph to graph as I want the text to be the title of the file so to avoid any confusion in the future (especially when I export the files in a powerpoint presentation). So would it be possible to do this using python to add the text in that position? Or alternatively to set the text box in the position I want in the template and modify the text in Python?

Thanks,
Tibi

YimingChen

1618 Posts

Posted - 06/27/2022 :  11:37:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You may call Labtalk script from Python to add text at the specified position. Try the example Python code below:

import originpro as op
graph = op.new_graph()
gl = graph[0] 
gl.lt_exec(f'label text_to_add') ## add label to the layer.
go = gl.label('text') ## get the text object
go.set_int('left', 2840) ## set text position
go.set_int('top', 5000) 
go.set_int('attach', 0) ## attach the text object to layer
gl.lt_exec('pfit2l') ## fit the page to layers

Here Labtalk command label is called from Python to place the label. Please refer to the page on the label command.
https://www.originlab.com/doc/LabTalk/ref/Label-cmd

James

Edited by - YimingChen on 06/27/2022 11:55:12 AM
Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 06/27/2022 :  5:00:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks. And how do I set the fontsize? I had a look in the link you posted, but couldn’t spot it. Is it \p200?
Go to Top of Page

YimingChen

1618 Posts

Posted - 06/27/2022 :  5:16:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
go.set_int('fsize', 22)

set_int() method here is to set graph object properties using Python. You can find the list of graph object property on this page:
https://www.originlab.com/doc/LabTalk/ref/Graphic-objs

James

Edited by - YimingChen on 06/27/2022 5:19:41 PM
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