238 lines (175 with data), 8.5 kB
@header@
<h2>matplotlib backends</h2>
The matplotlib core graphics routines interact with an abstract
renderer and graphics context to allow device independent ouput.
Currently, output to pygtk, wxpython, postscript, gdmodule and
libart/paint are supported. With not too much effort, you can port
matplotlib to your favorite display; high on my list of priorities are
SVG, PDF, Tkinter and PIL. If you are interested in porting to one of
these platforms, please contact me!<p>
You can choose your backend renderer from the command line prompt.
Most if not all matplotlib scripts can generate output to any of the
backends without any alterations. Following the lead of the matlab
<tt>print</tt> command, the backend can be chosen from the command
line with the <tt>-d</tt> flag, as in
<pre>
> python subplot_demo.py -dGTK # the GTK backend
> python subplot_demo.py -dPS # the postscript backend
> python subplot_demo.py -dGD # the GD backend
> python subplot_demo.py -dWX # the WX backend
> python subplot_demo.py -dPaint # the Paint backend
</pre>
For backends that do not have a GUI, no output will be produced unless
a call to <a href=matplotlib.matlab.html#savefig>savefig</a> is made.
The recommended way to use the savefig function is to not give an
extension. The backends will choose the proper extension. This
allows you to write a single script and select the output format from
the command line. So a script containing <tt>savefig('somefile')</tt>
will create <tt>somefile.ps</tt> if called with <tt>-dPS</tt> and
<tt>somefile.png</tt> if called with <tt>-dGD</tt>, and so on.<p>
Alternatively, you can select the backend renderer in your script by
calling the matplotlib <a href=matplotlib.matlab.html#use>use</a>
function. At the top of your script (before you <tt>import
matplotlib.matlab</tt>, just do, for example
<pre>
import matplotlib
matplotlib.use('PS')
</pre>
The current backend strings that are supported are <a
href=backends.backend_gd.html>GD</a>, <a
href=backends.backend_gtk.html>GTK</a>, <a
href=backends.backend_ps.html>PS</a> <a
href=backends.backend_ps.html>WX</a> <a
href=backends.backend_template.html>Template</a> and <a
href=backends.backend_paint.html>Paint</a>.
The default is GTK. Template is a do nothing backend that serves as a
template for backend writers (volunteers welcome!).<p>
To get the most of your backend of choice, you may need to set an
environment variable controlling the fonts; see <a
href="fonts.html">fonts</a> for more information.<p>
<h2>Backend requirements</h2>
Each of the backends have a different set of requirements, listed
below. All require the <a
href=http://sourceforge.net/projects/numpy>Numeric</a> module.<p>
<a name=GTK><h3>GTK</h3></a>
This is the default backend and the first one supported by matplotlib;
it requires
<ul>
<li><a href=http://www.pfdubois.com/numpy>Numeric</a></li>
<li><a href=http://prdownloads.sourceforge.net/gtk-win>
GTK runtime</a></li>
<li><a href=http://www.daa.com.au/~james/software/pygtk>pygtk</a>
version 1.99.16 or later</li>
</ul>
<h4>Redhat Users</h4>
GTK2 became the default with the Redhat Linux 8 series. If your
distro is older than that, you'll need to upgrade your desktop,
upgrade your gtk libs, or upgrade your distro.<p>
I am not sure what the status of GTK2 versus version number is with
the other distros, but I would be happy for answers, so if you know,
please email me @myemail@. If you put matplotlib in the subject,
the email will be sure to get past my spam filters.<p>
<h4>Windows Users</h4>
Windows users should consult <a
href=http://www.mapr.ucl.ac.be/~gustin/win32_ports>Cedric's pygtk
for win32 site</a> for information about pygtk for win32.
Basically, you need to install the <a
href=http://www.pcpm.ucl.ac.be/~gustin/win32_ports/>GTK 2.2.4
Runtime</a> and <a
href=http://www.pcpm.ucl.ac.be/~gustin/win32_ports/binaries/pygtk-2.0.0.win32-py2.3.exe>pygtk-2.0.0</a>
both of which have friendly windows installers. After you install
the runtime, you need to add the bin and lib subdirs of your
install dir to your PATH. Cedric's website also provides
pygtk-1.99.16 for python2.2 users which also works fine with
matplotlib.<p>
See the <a href=fonts.html>fonts</a> for more information about
getting the GTK backend setup for proper font rendering.<p>
<a name=WX><h3>WX</h3></a>
Requires <a href=http://www.wxpython.org>wxpython</a>. Windows users
may want to consider the <a
href=http://www.enthought.com/python>enthought edition</a> of python,
which comes with wxpython and Numeric built in
<a name=GD><h3>GD output</h3></a>
The GD module can be used to create images with no X11 server, and is
particularly useful for web application developers who want dynamic
graphing capabilities. There are a number of prerequisites but they
are easy to install.
<ul>
<li><a href=http://www.pfdubois.com/numpy>Numeric</a> --
Numeric processing in python</li>
<li><a href=http://www.boutell.com/gd>GD lib</a> -- The GD library.
Note if you are using linux and have this installed in /usr/lib, you
will need to install the latest version over the existing install
unless you have gd-2.0.15 or later</li>
<li><a
href=http://newcenturycomputers.net/projects/gdmodule.html>gdmodule</a>
-- The python interface to the gd module.</li>
<li><a href="http://fonttools.sourceforge.net/">font tools</a>Base
library for handling TTF fonts -- required by TTF query.</li>
<li><a href=https://sourceforge.net/projects/ttfquery/>TTF Query</a>-- A
python package for finding the best True Type font match for your
desired font. You must use version 0.2.6 or later</li>
<h4>Quick install guide for GD output</h4>
The latest snapshot of matplotlib requires a patch to
gdmodule-0.51. I contacted the maintainer and this will be folded
into the 0.52 release. Replace <a
href=gd/_gdmodule.c>_gdmodule.c</a> and install as below.
<pre>
cd /var/tmp
tar xvfz ~/src/gd-2.0.15.tar.gz
cd gd-2.0.15/
./configure --prefix=/usr
sudo make install
cd /var/tmp
tar xvfz ~/python/src/gdmodule-0.51.tar.gz
cd gdmodule-0.51
# apply new _gdmodule.c linked above
sudo python2.3 Setup.py install
cd /var/tmp
tar xvfz ~/python/src/fonttools-2.0b1.tgz
cd fonttools/
sudo python2.3 setup.py install
cd /var/tmp
tar xvfz ~/python/src/TTFQuery-0.2.6.tar.gz
cd TTFQuery-0.2.6/
sudo python2.3 setup.py install
</pre>
</ul>
See the <a href=fonts.html>fonts</a> for more information about
getting the GD backend setup for proper font rendering.<p>
<a name=Postscript><h3>Postscript</h3></a>
The only requirement is <a
href=http://sourceforge.net/projects/numpy>Numeric</a>
See the <a href=fonts.html>fonts page</a> for more information about
getting the postscript backend setup for proper font rendering;
notably, you must make sure there are some '*.afm' files in your
<tt>AFMPATH</tt> if you want to use fonts other than the ones that
ship with matplotlib.
<a name=Paint><h3>Paint</h3></a>
David Moore has written a paint backend for matplotlib. paint is a <a
href=http://www.levien.com/libart>libart</a> wrapper</a>. In a
nutshell, libart is a svg oriented, high performance, 2D graphics
engine that supports lots of nifty features. The paint backend
exposes some of them, and David has been extending it to expose more.
The paint backend requires <a
href=http://sourceforge.net/projects/numpy>Numeric</a>, <a
href=http://pypaint.sourceforge.net>pypaint</a> version 0.3. If you
want cross-platform freetype font selection support, you'll also need
TTFQuery and fonttools. See <a href=backends.html#GD>the GD
backend</a> for instructions on how to obtain and install these
modules. Otherwise the default font is <a
href=http://www.bitstream.com/categories/products/fonts/vera>Vera
Bitstream</a>, which ships with matplotib.
libart is highly portable, and the paint backend has been confirmed to
work on win32 and linux.
<a name=Debian><h3>Debian Users</h3></a>
Nelson Miner provided this information for debian. Debian has many
of the dependencies prepackaged
<pre>
> apt-get install python-numeric python-numeric-ext
> apt-get install fonttools libgd2-dev python-gtk2
</pre>
If you want to use the GD module, you'll still need to install
gdmodule and TTFQuery from src, as described in <a
href=backends.html#GD>the GD backend<a> above.
@footer@