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
 How to reduce time to generate Origin graphs?

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
ChemistryGuy Posted - 06/07/2022 : 8:11:04 PM
Origin Ver. and Service Release: 2022b
Operating System: Windows 11

I have written a script in PyCharm, which imports data to Origin and generates several graphs.

The problem is that this can take a long time, approximately 60 seconds. I compared this to generating similar plots of the same dataset using MatPlotLib, and it only took approximately 2 seconds.

I imagine that enabling speed mode, or turning off screen updating would accelerate this process. However, I could not find a way to do either of these from Python.

Therefore I wanted to ask: Please would you advise me if there is a way to reduce the time required to generate Origin plots using external Python?
4   L A T E S T    R E P L I E S    (Newest First)
ChemistryGuy Posted - 06/09/2022 : 7:12:45 PM
Thank you for explaining the reason for the improvement in speed, and for confirming this is the quickest way to run the script.

For your interest, I tried using the code you suggested:
gr = op.new_graph(template = tmpl, hidden=True)

But it made no difference to the speed for me. So I just used the approach of making origin itself invisible:
op.set_show(False)
minimax Posted - 06/09/2022 : 01:45:12 AM
No, I think it can not be faster now.

click Plot > Scatter with 4 cols of 8000 points does take 1.2 sec to finish drawing on my PC.

i.e. for yours 2.0279 vs. 0.1525, the diff time is spent on rendering the symbols on screen.

So script will be not faster than that.

op.set_show(False) is faster since it does not need to really draw the plot on the screen.

Instead of using op.set_show(False), you may try

gr = op.new_graph(template = tmpl, hidden=True)


It will also avoid to render the plot on the screen at the graph creation moment.

PS, another choice is changing to create line plot if it is acceptable, which is in general faster than scatter.


ChemistryGuy Posted - 06/08/2022 : 7:07:24 PM
Hi minimax,

Thank you for getting back to me, to answer your questions:

1. There are ~8,000 X values. Then there are 4 Y values for each X. So in total there are 32,000 data points to be plotted.
2. If I select the worksheet in Origin and click Plot > Scatter, it is almost instant. This is quicker
3. See below for a simplified code example, to demonstrate the issue.

However, I think I solved this issue myself in the meantime. I realised that op.set_show() is used to set the visibility of Origin.
I tried setting this to False instead of True, and found that it increased the speed by a factor of 10.

For instance, when I run the code with op.set_show(True), I get the following output:
Made plot in 2.0279 seconds
Made plot in 1.7737 seconds
Made plot in 1.7242 seconds

However, if I use op.set_show(False), I get the following output:
Made plot in 0.1525 seconds
Made plot in 0.0804 seconds
Made plot in 0.0778 seconds

Having said that, the plotting process is still 10 times slower than using MatPlotLib.
So it would be nice if it could be further accelerated, because I sometimes need to plot more graphs, each with more data points.
Please would you advise me if you have any other suggestions to improve the speed?


# Import data and specify tyemplate
# Full path to folder containing this script
op.set_show(True)
working_folder = os.path.dirname(os.path.realpath(__file__)) + '\\'
wks = op.new_book('w', hidden = True)[0]
wks.from_file(working_folder + 'mydata.csv', False) # Load mock data just for example
tmpl = working_folder + 'mytemplate.otpu'

for i in range(0, 3):
    # Start timer
    tic = time.perf_counter()

    gr = op.new_graph(template = tmpl)
    lay = gr[0]
    # Plot observed, calculated, background and difference as per template
    for i in range(1, 5):
            plot = lay.add_plot(wks, coly=i, colx=0)

    # Calculate the time spent
    toc = time.perf_counter()
    print(f"Made plot in {toc - tic:0.4f} seconds")

minimax Posted - 06/07/2022 : 10:34:00 PM
Hi,

How many points of the plot?

If you manually create the plot in Origin, is it fast?

And would you mind to share a piece of the plotting code?

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