Generating matplotlib graphs without a running X server

<>

This question already has an answer here:

Answers


@Neil's answer is one (perfectly valid!) way of doing it, but you can also simply call matplotlib.use('Agg') before importing matplotlib.pyplot, and then continue as normal.

E.g.

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

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

You don't have to use the Agg backend, as well. The pdf, ps, svg, agg, cairo, and gdk backends can all be used without an X-server. However, only the Agg backend will be built by default (I think?), so there's a good chance that the other backends may not be enabled on your particular install.

Alternately, you can just set the backend parameter in your .matplotlibrc file to automatically have matplotlib.pyplot use the given renderer.


You need to use the matplotlib API directly rather than going through the pylab interface. There's a good example here:

http://www.dalkescientific.com/writings/diary/archive/2005/04/23/matplotlib_without_gui.html


Need Your Help

Schema changes not updating in Intellisense in SQL 2008 (SSMS)

sql-server sql-server-2008 intellisense ssms

I've notice an issue - it feels like a bug but I suspect a 'feature' - in SSMS in SQL Server 2008.

Why are methods in Ruby documentation preceded by a hash sign?

ruby documentation

This is something that has been bugging me for a while. When I see any Ruby method printed in text, it usually appears as: