Menu

[r148]: / trunk / htdocs / fonts.html.template  Maximize  Restore  History

Download this file

89 lines (71 with data), 3.8 kB

@header@ 
<h2>Font handling</h2> 

I have spent a lot of time trying to make text in matplotlib look
good.  This has been a limitation of many pre-exisiting python
graphing solutions, but with the rise of freetype and anti-aliased
rendering for linux, it is now possible to have great looking fonts.

<h3><a name=TTFFONTS>Freetype fonts: GD, Agg, Paint</a></h3>

The GD, Agg, and Paint backends all support freetype fonts, which
provide high quality, anti-aliased font rendering to PNG and JPEG
output without X support.  This is particularly useful for batch
processing over terminal, or for web application servers. <p> 

You need to have '*.ttf' files on your system to use these fonts.  Set
the environment variable <tt>TTFPATH</tt> to point to your TTF
fonts.  A typical windows dir is <tt>C:\windows\fonts</tt>. matplotlib
distributes the 'Vera' fonts from bitstream, which were released under
a permissive license, and these are the defaults.  If you want more,
set the environment variable to point to them.  Note, if you are on
linux but have access to a licensed copy of windows ttf fonts, the
same <tt>*.ttf</tt> fonts in <tt>C:\windows\fonts</tt> will work with
matplotlib on linux if you place them in your TTFPATH.  Consult your
Windows EULA.<p>

Currently paint and Agg both use freetype1, which look great at high
resolutions but render poorly for lower resolutions.  If you are using
matplotlib to generate images for html, you may want to consider using
the gd backend, which supports freetype2.  freetype 2 tends to render
fonts better at very small raster sizes.  Look for freetype2 font
support in Paint and Agg in the near future.  See <a
href=faq.html#APPSERVER>matplotlib images in html</a> for more
information.<p>

For platform independent font finding, matplotlib uses fonttools and
TTFQuery.  Since several of the matplotlib backends now depend on
those packages, they are distributed with the src distribution and
will be installed automatically by the matplotlib windows installer.
If you want to build them with matplotlib yourself from src, set the
<tt>BUILD_TONTTOOLS</tt> flag in the matplotlib setup.py file.<p>

If you are aware of other freely distributable ttf fonts, please
contact me -  @myemail@.

<h3><a name=GTKFONTS>GTK</a></h3>

The most recent versions of GTK (2.2.4.1 and later) and pygtk-2.0.0
and later on linux have freetype font support built-in by default.  If
you are using an older version, set the environment variable
<tt>GDK_USE_XFT</tt>

<pre>
export GDK_USE_XFT=1    # bash and friends
</pre>

or

<pre>
setenv GDK_USE_XFT 1    # csh and friends
</pre>

If you are using GTK under windows, see <a
href=http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq21.011.htp>the
pygtk FAQ</a>.

<h3><a name=PSFONTS>Postscript</a></h3>

<a
href="http://www.adobe.com/products/postscript/main.html">Postscript</a>,
despite its age, is still a great output format.  Most publishers
accept it, it scales to arbitrary resolutions, you can import it
directly into LaTeX document, and send it directly to postscript
printers.<p>

The only requirement to generate postscript output is the Numeric
module and some AFM fonts on your system.  Even the latter is only a
quasi-requirement, because matplotlib ships with some of the most
popular font files.  These are <it>Adobe Font Metric</it> files, which
have the '*.afm' extension.  matplotlib comes with it's own AFM parser
to read these files and select the best match for the font you've
chosen.  If you want additional fonts, set the <tt>AFMPATH</tt>
environment variable to point to the dir containing your AFM font
files.  matplotlib willl recursively search any directory in
<tt>AFMPATH</tt>, so you only need to specify a base directory if
multiple subdirectories contaning '*.afm' files.<p>


@footer@
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.