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
 Python(OriginExt) Multiple plots on same graph

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
Salman4750 Posted - 05/29/2020 : 4:22:43 PM
I have tried to connect the Python with Origin using OriginExt.
I have created a simple Scatter plot but now I am wondering how to add more variables. For Example instead of having one if I have to plot 2-3 Variables at the same time. How I can add multiple layers and plot multiple graphs.


salman
5   L A T E S T    R E P L I E S    (Newest First)
Salman4750 Posted - 06/05/2020 : 06:07:51 AM
Thank you for your reply.

salman
Sam Fang Posted - 06/04/2020 : 05:53:37 AM
Hi salman,

We made an example to show how to connect Origin in Python using OriginExt to create graphs. You can download the zip file in the link:
https://www.dropbox.com/s/trgoq3ia5jskhwj/OriginExtGraph.zip?dl=0

You can place the project file "PyGraphEx.opju" in the zip file to Origin's User Files folder. Create a folder C:\Test for the folder of the created image, run the py file in the zip file, and it will create a graph to replace the project's data with data specified in py file, and export the created graph to your defined folder. In this way you can plot any number of variables in Python.

Note that if you want to run the py file without opening Origin, you must open Origin by Run as administrator at least once.

The created graph by py file is shown as below:


The Python script is pasted here:

#This example requires to install OriginExt package
import OriginExt as oe

#keep one copy of Origin running only
app = oe.ApplicationSI()
app.Visible = app.MAINWND_SHOW

#Assume the sample project file is in Origin's User Files folder
uff = app.Path(app.APPPATH_USER)
strOpju = uff + 'PyGraphEx.opju'

app.Load( strOpju, False )

bkNames=['Book1', 'Book2']
#Change y data in Book1 and Book2 with following data and update graph
bkData = [ [20.89296, 0.22387, 54.95409, 0.10471, 1.90546, 60.25596],
           [0.00251, 0.00354, 0.00225, 0.00383, 0.00296, 0.0023],
           [0.20893, 5.7544, 1.04713, 2.51189, 0.1122, 24.54709, 0.70795],
           [0.00475, 0.00325, 0.004, 0.00359, 0.00512, 0.00278, 0.00406],
           [3.23594, 54.95409, 0.14454, 4.46684, 0.6166],
           [0.00418, 0.00282, 0.0066, 0.004, 0.00536],
           [23.98833, 1.58489, 34.67369, 13.18257, 75.85776],
           [0.0068, 0.00957, 0.00658, 0.00724, 0.00584],
           [95.49926, 5.01187, 10.47129, 1.25893, 9.77237, 16.2181, 23.44229],
           [0.00631, 0.01006, 0.00875, 0.01224, 0.00896, 0.00819, 0.00769],
           [10.71519, 11.74898, 89.12509, 1.12202, 32.35937, 1.44544] ]

for i, strbk in enumerate( bkNames ):
    sheet = app.FindWorksheet( strbk )
    bk = sheet.Parent
    #Change data in first three sheets in each book
    for j in range(3):
        bk[j].SetData( bkData[ 2*j+6*i : 2*j+2+6*i ] )

#Delete Book3 and the legend for its curves in the graph
app.DestroyPage('Book3')

gl = app.FindGraphLayer( 'Graph1' )
#Execute LT on the context of the graph layer
gl.LT_execute( 'label -r Legend3;' )

#Force to recalculate apparant linear fit before exporting graphs
app.LT_execute( 'run -p au;')

#Export Graph1 to a custom folder. File name is Test.png and width is 2000.
imgPath='C:\\Test'
app.LT_set_str( '%A', imgPath )
gp = gl.Parent
gp.LT_execute( 'expGraph type:=png filename:=Test path:=%A overwrite:=replace tr1.Unit:=2 tr1.Width:=2000' )

print( 'Graph is exported to: %s\Test.png .' %(imgPath) )

#Exit Origin
app.Exit()
del app


Sam
OriginLab Technical Services
cpyang Posted - 05/30/2020 : 11:25:53 AM
Ok, so it is one layer and there are some fit curves as well.
Still, the simplest way to do this is to prepare an OPJU with 3 sets of plots. Then based on number of sets, you delete the books that are not needed, and the plots are automatically removed.

You do need to make each legends and name them, and delete the unused legend by name according to how it was set up.

We can make a complete sample to share here.

CP
Salman4750 Posted - 05/29/2020 : 10:24:54 PM
Thanks for the reply.
In attachment, you can find the required Graph which I want to draw using python. Actually my idea is to def a function that automatically takes all the variables you have and plot them on the same graph so it can be further used for analysis. I have plotted with one variable but now I am having difficulty to plot the second variable on same graph.




salman
cpyang Posted - 05/29/2020 : 5:07:01 PM
The simplest if would be to prepare these graphs ahead of time and simply replace the data accordingly, like prepare an OPJU and depending on which situation, push in the data in a different sheet and the connected graph will just automatically update.

You want the graph to have like vertical stack of different number of layers right? It is much easier to manually manipulate such graph in Origin and save either as template or as part of a project.

CP

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