Converting matplotlib plots to Igor Pro graphs
In my experience dealing with PhD students, who know python well, their difficulty transitioning to Igor Pro for data visualization and analysis is that it's not easy to reproduce a matplotlib graph as an Igor Pro graph.
Although they realize the power of Igor Pro once the graph is displayed and we have cursors, zoom, pan, fitting, etc, the process of converting numpy data into Igor Pro and then displaying it is complex.
Python integration in Igor Pro 10 is great progress towards leveraging the benefits of both, but I would like an additional feature to convert a matplotlib graph into an Igor Pro graph. This could be implemented as
1. Standalone python module which exports a graph `pxp` given a matplotlib plot
2. In an Igor Pro 10 python session, a function in the `igorpro` module which, given a matplotlib plot object, generates the Window recreation procedure to create the corresponding graph
This is not an easy task as matplotlib is a huge module, but the conversion module could be built incrementally, focusing on the simplest types of plots first. For Python users who are adept with matplotlib, seeing the equivalent Igor Pro code to generate their plot would help them learn Igor Pro.
I would be happy to help develop this.
Here's an example, coded with Claude:
October 30, 2025 at 07:50 am - Permalink
That's an interesting idea, and probably doable for simpler graphs. I imagine you could at least get 'close enough' to the matplotlib graph as a starting point for making further modifications in Igor. As a potential alternative to saving Igor commands in an .itx file, you could also generate the graph directly from Python by taking advantage of the `igorpro.execute()` method, which allows you to execute any arbitrary Igor code. Here's a first pass at converting the graph you provided into a graph in Igor. Some things like the grid lines and legend are missing, but you get gist. You pass the 'fig' object in to the 'convert()' method after your code is finished running:
October 30, 2025 at 01:10 pm - Permalink
For developing this, I created a public git repository that I'll be 'casually' working on (benmurphybaum/IgorPlot: Converting matplotlib plots into Igor graphs using Python). Feel free to clone it and submit pull requests for any code you (or anyone else) wants to add. There are some instructions on setting up the project in the readme. I have also included some Igor code that will automate creating a virtual environment for the project and installing the dependencies -- I'd recommend starting there.
As of today, it will convert simple line plots reasonably well, but other graph types are not implemented yet. Once the graph is converted and displayed in Igor, you can create a graph recreation macro to save the Igor commands that will regenerate the graph.
DoWindow/R NameOfGraphThe code that will regenerate the graph is saved into the main procedure file in Igor. This is going to be one of your best resources for your students to use to get a feel for the Igor commands needed to customize graphs.
October 31, 2025 at 10:54 am - Permalink
From the sidelines ...
* Consider using the approach ... for index, trace in enumerate(axis.get_lines()) ... rather than using an explicit i = 0 and i += 1 approach
* Consider capturing the translations of the python code into Igor Pro code being dumped a text string, dumped to a procedure file or notebook, and executed via a call igorpro.execute(f"create_py2IPplott()").
* As a step further to the above, separate the translation of python->Igor Pro actions into two parts. The first part is a routine that captures all the plot trace data into waves in a specific root:pythonplot data folder. The second part is a routine that displays waves from the data folder root:matlibplot and applies the given graph style. The latter routine could even be built to create a WinRecreation. Both routines could eventually be designed to become standard sub-modules to the igorpro python library, accessible for example via #import igorpro.captureplottraces or #import igorpro.capturegraphstyle.
Essentially, users of python could eventually be instructed to do the steps below to translate python plots to Igor Pro plots.
October 31, 2025 at 12:54 pm - Permalink