Accessing Origin’s Graphing Power from Python

Introduction

Origin 2021 came with much improved embedded Python support. But it also brought support for accessing Origin from Python installations external to Origin. And similarly to how you can use the originpro Python package in embedded Python, you can use it with external Python.

In this blog post, I’ll show you the easiest way to generate great Origin-based graphs from external Python. For example:

The Plan

The plan is to create an Origin project file ahead of time to serve as a template project for the graph you want to create via Python. You will create a new workbook (or matrixbook) with an example of your data and then create the graph of your choice. Now is your chance to do whatever you want with the graph- customize it exactly the way you want.

The only big consideration is whether you foresee that the real data will vary from the example to the point where the axes ranges may change. If you see that as a possibility, account for that in the Axis Dialog (e.g. set the Axsis Scale Rescale to Auto).

You will want to make a note of the short name of the workbook because you are likely to need it in your script.

Finally, you can optionally delete your example data from the worksheet and save the Origin project file to make the file size smaller.

Please download the zip file for this blog. There is an Origin project file template.opju and python file script.py.

The Python

Rather than trying to explain what needs to be coded, I simply commented the script in zip file below really well so you can learn from it. It is meant to operate with the template project included in the zip file. As long as the script and template OPJU file are in the same folder, all should work properly. By the way, you’ll need to install numpy. You can check and install it in Python Packages dialog opened by Connectivity: Python packages menu.

Conclusion

I hope this post was enlightening and helps you learn how to access Origin from external Python.

About Chris Drozdowski

Chris Drozdowski is a Product Support Engineer at OriginLab. He loves to talk to customers and educate them. He particularly relishes diagnosing and solving difficult, edge-case issues. As well, he contributes code to help solve problems or enhance user experience. In his down time at work, he likes to research and write about esoteric product features. Outside of work, he enjoys spending time with his family, having fun with C++, working on his aquarium, and exploring craft beers.

View all posts by Chris Drozdowski →

Leave a Reply

Your email address will not be published. Required fields are marked *