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 Origin C
 Plotting in Origin with Python

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
ryuutakenaka Posted - 10/27/2014 : 11:05:09 PM
Origin Ver. and Service Release : 8.0
Operating System: Win 8

Hi,

Is there an easy way to plot data in Origin with Python? I managed to connect to Origin through COM module, by following this guide:

http://ocwiki.originlab.com/index.php?title=OriginCOM:Application-PutWorksheet

It's working fine but now I also need to make a simple line plot of the data from the worksheet, set some axes titles, scale, etc. I can't find any information on how to do this in Python. Can anyone help?

Thank you,
Ryuu
5   L A T E S T    R E P L I E S    (Newest First)
VladGets1 Posted - 11/04/2016 : 09:24:25 AM
quote:
Originally posted by ryuutakenaka

Origin Ver. and Service Release : 8.0
Operating System: Win 8

Hi,

Is there an easy way to plot data in Origin with Python? I managed to connect to Origin through COM module, by following this guide:

http://ocwiki.originlab.com/index.php?title=OriginCOM:Application-PutWorksheet

It's working fine but now I also need to make a simple line plot of the data from the worksheet, set some axes titles, scale, etc. I can't find any information on how to do this in Python. Can anyone help?

Thank you,
Ryuu



I advise you to read the blog about Python http://djangostars.com/blog/python-in-a-1000-words/
ZanHUNG Posted - 10/28/2014 : 11:29:39 PM
quote:
Originally posted by ryuutakenaka

Another question... Now I'm trying to make a folder inside my Origin project with the code, adapted from VB example available here:
http://ocwiki.originlab.com/index.php?title=OriginCOM:Folders-FolderFromPath#VB

The simple code:
import win32com.client 

origin = win32com.client.Dispatch("Origin.ApplicationSI") 
origin.visible = 1

fldr = origin.RootFolder.Folders
fldr.Add("sample folder")

is giving me a "pywintypes.com_error: (-2147352573, 'Member not found.', None, None)"

What am I doing wrong?



That works in VB. In Python, the code should be
fldr = origin.RootFolder.Folders.Add
fldr.Name = "sample folder"

or simply
origin.RootFolder.Folders.Add.Name = "sample folder"
ryuutakenaka Posted - 10/28/2014 : 4:59:38 PM
Another question... Now I'm trying to make a folder inside my Origin project with the code, adapted from VB example available here:
http://ocwiki.originlab.com/index.php?title=OriginCOM:Folders-FolderFromPath#VB

The simple code:
import win32com.client 

origin = win32com.client.Dispatch("Origin.ApplicationSI") 
origin.visible = 1

fldr = origin.RootFolder.Folders
fldr.Add("sample folder")

is giving me a "pywintypes.com_error: (-2147352573, 'Member not found.', None, None)"

What am I doing wrong?
ryuutakenaka Posted - 10/28/2014 : 12:50:26 PM
Thank you very much for your extensive reply! I was unable to set DataRange before. Also, LabTalk will be useful, as I want to make multiple graphs with different, dynamically assigned axes scale.

Here's my minimal working example if anyone wants to use it in future (working in Python 3.4.2):

import random # for creating random data
import win32com.client # COM module for communication with Origin

# Connect to Origin
origin = win32com.client.Dispatch("Origin.ApplicationSI") 
origin.visible = 1 # Make Origin window visible

# Create a new workbook named "Python" using the "origin" template
pageName = origin.CreatePage(2, "Python", "origin")

# Put the X and Y data into the worksheet
xData = range(0, 101, 2)
yData = [random.random() for x in xData]
origin.PutWorksheet(pageName, xData, 0, 0) # row 0, col 0
origin.PutWorksheet(pageName, yData, 0, 1) # row 0, col 1

# Create a Data Range
wks = origin.FindWorksheet(pageName)
dr = wks.NewDataRange
dr.Add("X", wks, 0, 0, -1, 0)
dr.Add("Y", wks, 0, 1, -1, 1)

# Create a Graph Layer
gpname = origin.CreatePage(3, "PyGraph", "otp4py")

# Add Data Plot to Graph Layer
gl = origin.FindGraphLayer(gpname)
gl.DataPlots.Add(dr, 200)

# Manipulate format settings (if Graph Template "otp4py" is unavailable)
origin.Execute("y1 = -2; y2 = 2;", gpname) # set y scale from -2 to 2
origin.Execute("x1 = 0; x2 = 100;", gpname) # set x scale from 0 to 100
origin.Execute("label -xb X Title;", gpname) # set x axis title to "X Title"
origin.Execute("label -yb Y Title;", gpname) # set y axis title to "Y Title"

# Clear all variables
import sys
sys.modules[__name__].__dict__.clear()


I need to clear all variables at the end, otherwise it won't let me close Origin saying that "another application is controlling Origin"

Topic resolved and can be closed.
ZanHUNG Posted - 10/28/2014 : 03:22:13 AM
quote:
Originally posted by ryuutakenaka

Origin Ver. and Service Release : 8.0
Operating System: Win 8

Hi,

Is there an easy way to plot data in Origin with Python? I managed to connect to Origin through COM module, by following this guide:

http://ocwiki.originlab.com/index.php?title=OriginCOM:Application-PutWorksheet

It's working fine but now I also need to make a simple line plot of the data from the worksheet, set some axes titles, scale, etc. I can't find any information on how to do this in Python. Can anyone help?

Thank you,
Ryuu



Both Python 2.7 and Python 3.3 have been embedded in Origin 2015 just released a few hours ago....

There are examples about plotting, though not in Python, in http://ocwiki.originlab.com/index.php?title=OriginCOM:Plotting

After sending data to worksheet, you may create a DataRange before plotting like this:

wks = origin.FindWorksheet(pageName)
dr = wks.NewDataRange
dr.Add("X", wks, 0, 0, -1, 0)
dr.Add("Y", wks, 0, 1, -1, 0)

And, of course, a GaphLayer as well:
gpname = origin.CreatePage(3, "PyGaph", "otp4py")


Now you can add DataPlot to it:
gl = origin.FindGraphLayer(gpname)
gl.DataPlots.Add(dr, 200)

"200" means a line plot. See http://ocwiki.originlab.com/index.php?title=OriginCOM:PLOTTYPES for more.

About format setting (axes titles, scales, etc.), you can do this either by Graph Template or LabTalk script:

1. See the "otp4py" in red above, it's the name of a graph template saved before. You don't have to bother about format setting so long as it can be pre-defined.
http://www.originlab.com/doc/Origin-Help/Plot-Graph-Template

2. If you know some LabTalk, then have a try of Execute(). For example, to change the y scale from -2 to 2:
origin.Execute("y1 = -2; y2 = 2;", gpname)

To change X title:
origin.Execute("label -xb X Title;", gpname)


http://ocwiki.originlab.com/index.php?title=OriginCOM:Application-Execute
http://www.originlab.com/doc/LabTalk/ref/Label-cmd
http://www.originlab.com/doc/LabTalk/ref/Layer-Axis-obj


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