[Pythonmac-SIG] matplotlib and postscript output

Samuel M. Smith smithsm at samuelsmith.org
Fri Sep 9 18:04:30 CEST 2005


You can make the use of tex automatic by setting text.usetex to True  
in your rc file

### TEXT
# text properties used by text.Text.  See
# http://matplotlib.sourceforge.net/matplotlib.text.html for more
# information on text properties
text.color          : black
text.usetex         : True  # use tex/latex for all text handling.   
See http://matplotlib.sf.net/matplotlib.texmanager.html
text.tex.engine     : latex  # tex is faster, but latex is required  
to use special font packages


The default tex font is a serif. The distribution texmanager ignores  
the font.family in the rc file.
Robert Kern provided another fix:

add to the top of  the get_tex_command in
matplotlib-0.83.2/lib/matplotlib/texmanager.py

the following
fontcmd = {'sans-serif': r'{\sffamily %s}',
            'monospace': r'{\ttfamily %s}'}.get(rcParams['font.family'],
                                                r'{\rmfamily %s}')
tex = fontcmd % tex


This is what mine looked like

def get_tex_command(self, tex, fname):
         fh = file(fname, 'w')

         #Added by SamuelSmith so tex respects font-family from rc file
         fontcmd = {'sans-serif': r'{\sffamily %s}',
            'monospace': r'{\ttfamily %s}'}.get(rcParams['font.family'],
                                                r'{\rmfamily %s}')
         tex = fontcmd % tex

         #End addition


Then reinstall matplotlib

Now your plots use the font.family  for text so you can select serif  
or sans-serif
for example

font.family         : sans-serif



More information about the Pythonmac-SIG mailing list