Using matplotlib / pylab without a DISPLAY

I’ve been having issues with a web system I coded for a while now and couldn’t find a solution that worked to my satisfaction to eliminate the need of a Xvnc running to provide a virtual DISPLAY to run some commands to plot data using pylab.

Finally, today, I found the solution here and I want to share it.

import matplotlib
matplotlib.use('Agg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt

fig = plt.figure()
plt.plot(range(10))
fig.savefig('temp.png')

The solution, here, is the Agg option as the “device” to be used to plot files.

Solution in place, and I can now eliminate the requirement for Xvnc from my code and all the issues that came with it are also automatically gone.

So, here’s the code for Pylab:

import matplotlib
matplotlib.use('Agg') # Must be before importing matplotlib.pyplot or pylab!
import pylab

pylab.plot(range(10))
pylab.savefig('temp.png')

Enjoy!

It is something different — and getting popular

One of my clients is amazed at how one of our websites is getting attention from people from all over the world.

He’s been mentioning about somebody in Atlanta that has been using the site for two weekends in a row, using the site for two consecutive days last weekend.  “And the website is only in Portuguese!” he says.

We have both created a tool to work with curve fitting using R as the software base for the curve fitting algorithm.  It is still just a concept, but we have already decided on expanding that to include other algorithms besides linear fitting.  And we’re willing to make adjustment to points according to the equation from the curve.

Simple, yet efficient.

Of course, for the next version I’ll sneak in an English translation.  I still haven’t tried implementing any I18Nization with R (I’ll probably need to convert from lazystrings to Unicode before passing the string to R, though…), but it should work fine.