Pyqtgraph extensions package

Over the past year year I’ve been using pyqtgraph extensively, both for laboratory apps and publication plots. I’ve been able to make some reasonably complex plots:

ic_o-xylene_theta_scan_0-3e14orbitals_inkscape

What I like most about pyqtgraph is the underlying use of Qt for layout management, the performance and the logical design of its internals, which makes extensions not too difficult to develop. However I have found it lack a bunch of features that I need – probably because I’m using it for static publication plots as well as in GUIs. I’ve bundled the various solutions that I’ve developed into a package pyqtgraph_extensions. It adds a bunch of features such as simplified exporting, a MATLAB-like colorbar and more powerful alignment of plots.

 

pygraph and matplotlib together

Isosurfaces aren’t in the core matplotlib library, although they are certainly possible. Because of this, and my keenness to keep experimenting with pyqtgraph, I made a hybrid solution:Screenshot from 2016-01-03 23:42:27

The left plot is done with pyqtgraph, and the right with matplotlib. The whole thing is a QWidget, its layout managed by Qt. The MatplotlibWidget class in pyqtgraph conveniently holds the matplotlib figure on the right.

I made a few customizations to pyqtgraph:

  1. A GLAxisItem (the yellow, green and blue lines indicating the coordinate axes) subclass that makes the lines thicker and adds text labels.
  2. A GLViewWidget subclass that corrects the default Qt sizeHint of the original, which is (-1,-1) and causes the widget to not be displayed. This corrects a known issue.

Testing Python for my kind of scientific computing

In my ten years as an laser physicist, I’ve had to code a plethora of experimental and theoretical programs. I need a variety of tools: live image acquisition, PC-scale number crunching, reasonably advanced GUIs, publication quality plots. To maximise learning investment, I wanted a single language environment. After some serious attempts with LabVIEW and C/C++, I settled upon MATLAB as the best compromise.

For a bunch of reasons I’m now testing out Python. As a first attempt I starting porting a code for calculating high-harmonic spectra from complex molecules (>12 atoms, complex for a physicist) as part of an ongoing analysis of some recent experiments. In principle, the calculation itself isn’t too demanding – it is manageable on a powerful desktop. The challenges are:

  1. Translating my MATLAB vectorization paradigms, which revolve around the wonderful bsxfun command, into Python’s de facto standard for numerics, Numpy.
  2. Reproducing my plots, which involve a mixture of 2D and 3D and can get reasonably complicated:Screenshot from 2016-01-03 23:19:35

In the next post I’ll discuss some of this.