218 lines (165 with data), 8.1 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, postscript and gdmodule are supported, and
wxwindows is under active development. 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 - alpha version
</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 (
<i> this is a design decision that I am not committed too. The
primary alternative is to print to stdout. This would enable you to
use the postscript backend with, eg, <tt>python subplot_demo.py -dPS |
lpr</tt> but for unsuspecting users could result in a lot of ASCII
dumped to the screen. If you have a preference, weigh in </i>). I
have made a minor change to <a
href=matplotlib.matlab.html#savefig>savefig</a> -- the recommended way
to use this 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('GTK')
</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> and <a
href=backends.backend_template.html>Template</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 only one supported in early
versions of matplotlib; it requires
<ul>
<li><a href=http://www.pfdubois.com/numpy>Numeric</a></li>
<li>GTK2</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>
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>. This is a
development version and is released primarily for testing and
debugging. See the code matplotlib/backends/backend_wx.py for a
report on existing features and known bugs. If you have wxpython
installed, you can take it for a test drive with <tt>python
yourscript.py -dWX</tt> and please report any bugs not listed in the
KNOWN BUGS section of the wx src to the <a
href=http://sourceforge.net/mailarchive/forum.php?forum_id=36187>matplotlib-devel</a>
mailing list.
<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
installunless 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>
<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.42.tar.gz
cd gdmodule-0.42/
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=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@