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
 Export graph as PDF
 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/2023 :  12:08:01 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2021b and Service Release SR2 (Select Help-->About Origin):
Operating System: Win10 Ent

Is it possible to use a code to export a graph from Origin to PDF?

Thank you!

ChaoC

USA
178 Posts

Posted - 06/27/2023 :  2:13:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

You can use the originpro function save_fig().

e.g.
g = op.find_graph('graph1')
g.save_fig('C:\\ExportFolder\\' + 'Image.pdf', width=500)

https://docs.originlab.com/originpro/classoriginpro_1_1graph_1_1GPage.html#abc11d7878e4df6a2b8e91f4d8bf73958


Or you could use the originpro function lt_exec() to run the LabTalk command for graph exports.

e.g.
op.lt_exec('expGraph type:=pdf')

https://docs.originlab.com/originpro/namespaceoriginpro_1_1utils.html#a32f4ba8d0e3bc42d938e25c8be5ec749
https://www.originlab.com/doc/X-Function/ref/expGraph

Best,
Chao
Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 06/28/2023 :  09:01:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have tried the first solution but it did not work. I am getting the following error: AttributeError: 'NoneType' object has no attribute 'save_fig'

This is the code I use:
gr1 = op.new_graph(template=(new_path_template + '\\Origin templates\\htcd_12.otpu'), lname=f'{title_spectra.group()} and {title_base.group()}')
gls = [gr1 for i in range(len(htcd_file.columns)-1)]
p = ['' for i in range(len(htcd_file.columns)-1)]
p_base = ['' for i in range(len(htcd_file.columns)-1)]

for i in range(len(htcd_file.columns)-1):
p[i] = gr1[i].add_plot(wks, coly=f'{i+1}', colx='A')
p_base[i] = gr1[i].add_plot(wks_baseline, coly=f'{i+1}', colx='A')
p_base[i].color = "Blue"
gls[i].xlim = (min_wavelength, max_wavelength)
g = op.find_graph('gr1')
g.save_fig()

I have tried the second option as well which did not throw out any error, but I don't know either the name or the location of the file.




quote:
[i]Originally posted by ChaoC


Hello,

You can use the originpro function save_fig().

e.g.
g = op.find_graph('graph1')
g.save_fig('C:\\ExportFolder\\' + 'Image.pdf', width=500)

https://docs.originlab.com/originpro/classoriginpro_1_1graph_1_1GPage.html#abc11d7878e4df6a2b8e91f4d8bf73958


Or you could use the originpro function lt_exec() to run the LabTalk command for graph exports.

e.g.
op.lt_exec('expGraph type:=pdf')

https://docs.originlab.com/originpro/namespaceoriginpro_1_1utils.html#a32f4ba8d0e3bc42d938e25c8be5ec749
https://www.originlab.com/doc/X-Function/ref/expGraph

Best,
Chao

Go to Top of Page

ChaoC

USA
178 Posts

Posted - 06/28/2023 :  09:27:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

find_graph() uses the Short Name of the graph. I don't think you have a graph with the Short name 'gr1'.
Also, your code currently doesn't specify the filename or format.
You will want to put something like: g.save_fig('example.pdf').

For the second option, expGraph has options to set filepath and filename, please see the documentation.

Best,
Chao
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