In July 2011 I moved to Harvard University to join the School of Engineering and Applied Sciences. My new web page is here.

XML for Matplotlib

Matplotlib is a library for Python that is incredibly useful. It generates lovely plots that are of publication quality. You can look at a nice collection of screenshots here.

xmpl (XML for Matplotlib) is a tool that allows you to use Matplotlib without knowing any Python. You create an XML document in a particular format, and then run xmpl on that document. You will get as output an image file. The data you wish to use for generating the plot is part of the XML file.

One particularly useful aspect of xmpl is to use it with another piece of code that I have here: Template::XMPL which is a Perl plugin for the Template Toolkit. Along with the Catalyst framework, the idea is to generate dynamic plots on your website in the same templated way that you generate dynamic database-backed text content.

Things are a little annoying right now because Matplotlib doesn't seem to be available for Python 2.5 on Ubuntu Gutsy. The APIs for these things are a little dynamic, so you might have to do some tweaking to get it to work. Hopefully Matplotlib, Scipy and various Python tools will settle down so you won't have to have the latest SVN checkout for the documentation to do what it says. (It is nice that there's active development, though.)

Here is an example to show you most of the interesting bits. It's not exactly feature-complete, but you get the idea:


<!-- set axis labels --> <xlabel text="The x-axis label" /> <ylabel text="The y-axis label" /> <!-- want a grid? insert this. --> <grid /> <!-- define one or more series --> <series> <!-- the data are inline --> <datum x="1.0" y="2.0" /> <datum x="2.0" y="-6.0" /> <datum x="3.0" y="12.0" /> <datum x="4.0" y="-6.0" /> <datum x="5.0" y="3.0" /> <datum x="6.0" y="-4.5" /> </series> <!-- you can also have series styles, colors, etc. --> <series style="ro-"> <!-- the data are inline --> <datum x="1.0" y="-2.0" /> <datum x="2.0" y="6.0" /> <datum x="3.0" y="-12.0" /> <datum x="4.0" y="6.0" /> <datum x="5.0" y="-3.0" /> <datum x="6.0" y="4.5" /> </series> </plot> </figure> </pre> <p> That code generates this:<br/> <img src="images/example1.png" /><br/> The basic usage is "xmpl infile.xml outfile.png" with "--verbose" if you want it. </p> <p> Here is another example that was generated dynamically using <a href="Template-XMPL.shtml"> Template::XMPL</a>. It has a series that is the raw data, plus a Gaussian process regression with error bars. The templated code that generated this is on the Template::XMPL page. It uses dates on the x-axis, which you might find useful.<br/> <img src="images/plotweight.png" /> </p> <p> <a href="code/xmpl">download xmpl</a> </p> </div> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-1206190-4"; urchinTracker(); </script> </body> </html>