Other things on this site...

Evolutionary sound
Listen to Flat Four Internet Radio
Learn about
The Molecules of HIV
Make Oddmusic!
Make oddmusic!

Open-source 3D plotting on Mac

I've been working on Self-Organising Maps for timbre analysis, and I needed a good way to make an interactive 3D plot of the SOMs so that I could visually verify what was going on. ... Actually it took me a while trying out a few options, to get something decent in place. That's why I'm documenting it here.

  • Of course Matlab has some good scientific 3D plotting, and I did a couple of preliminary visualisations using that. However, it's not open-source, it doesn't dovetail particularly nicely with SuperCollider (which is where my data is coming from), and it is a bit of a behemoth and I don't want it installed on my tiny Linux Eee PC.
  • GNU Octave is pretty much an open-source clone of Matlab (it aims for language compatibility). It provides some basic matlabby plotting but lacks a lot of the advanced control, and also some features such as patch() are missing, which I needed.
  • My number 1 hunch was that Python, with its popular scientific modules, would have some powerful 3D plotting right there. However, the standard matlab-like plotting module matplotlib doesn't have any 3D support. There's also something called mayavi which I think does OpenGL-based fancy 3D graphics, but I couldn't get it installed on my Mac so I couldn't test it out. I was really surprised not to be able to get very far with python and scientific 3D.
  • Someone reminded me about scilab - silly of me to forget this one; it's a long-standing open-source science platform with visualisation tools, I bet it could have helped.

And here's the solution I finally settled on:

  • gnuplot, plus the GNUPlot quark to be able to use it directly within SuperCollider. Gnuplot has a nice diversity of plotting styles available from its scripting language, and in the end it was surprisingly simple to script it to build what I wanted: 3D surface plots with little lines sticking out, representing the mapping from datapoints onto the SOM. It took me a while to understand that it's not oriented towards inline data: it gets much easier if you drop your data into a text file (CSV or suchlike) and work from that.

Here's an example of some test data which I piped straight from SuperCollider into gnuplot:

it works!

Tuesday 12th May 2009 | IT | Permalink
Name: Lee Phillips
Website: http://lee-phillips.org
Email: lee art lee-phillips dort org
Date: Thursday 14th May 2009 18:15
I've also found that gnuplot is one of the few open source programs that can produce high-quality 3d surface plots. You can use matplotlib to display the same information as an image or contour plot, but sometimes you need the surface (and with hidden line removal, which gnuplot does quite well). But I've also had some luck using PyX (http://pyx.sourceforge.net/), which can also produce surface plots. This is a python package that makes pdf files directly. Plot generation is less automatic than with gnuplot, but you can get some pretty results with a lot of control.
Name: Dan
Website: http://www.mcld.co.uk
Date: Thursday 14th May 2009 18:47
Ah yes, thanks. I did also have a look at PyX, forgot to mention that one. It's pretty nice, and could be handy for producing documentation - but of course it doesn't do interactive plots (rotation by mouse), which has been important for me in understanding my data...

Add your comments:

I am a:
Everything is optional - and email addresses will be marmalised to protect you
Creative Commons License
Dan's blog articles may be re-used under the Creative Commons Attribution-Noncommercial-Share Alike 2.5 License. Click the link to see what that means...