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
 Forum for Python
 Export graph as PDF

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
cts18488 Posted - 06/27/2023 : 12:08:01 PM
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!
3   L A T E S T    R E P L I E S    (Newest First)
ChaoC Posted - 06/28/2023 : 09:27:15 AM
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
cts18488 Posted - 06/28/2023 : 09:01:28 AM
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

ChaoC Posted - 06/27/2023 : 2:13:06 PM
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

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