Thursday, November 29, 2012

Matplotlib without an X server

Short form, by running xvfb-run python script.py

In a more detailed answer, you need to install xvfb first:

$ sudo apt-get install xvfb

And then, supposing a script like this that we save as mpl.py:

from matplotlib.pyplot import *

plot([2,4,2,5,6,3,1])
savefig("graph.png")

We then run it:

$ xvfb-run python mpl.py
 There should be a file named graph.png that will look like:

 All from the console.

No comments: