Latex and font embedding

Hello,

I've been using Matplotlib to generate postscript (eps) graphics which I
import into my latex documents. I tried using Latex to typeset mathematical
symbols on my plots using the steps described here:

http://www.scipy.org/Cookbook/Matplotlib/UsingTex

The problem (I think) is that the eps files are genrated using dvipng, which
results in ugly figures in the final PDF output. Is there a way to get
Matplotlib to *not* use dvipng as the backend?

For example. If I use the following simple script to generate a eps file

···

=========================================
from matplotlib import rc
import pylab
from pylab import *
import numarray as na
params = {
        'backend': 'ps',
        'axes.titlesize': 24,
        'axes.labelsize': 18,
        'xtick.labelsize': 14,
        'ytick.labelsize': 14,
        'legend.fontsize': 14
        }
pylab.rcParams.update(params)
#rc('text', usetex=True)
N = 4
ind = arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
data01 = (5, 10, 3, 2)
data02 = (3, 7, 10, 6)
title('Normal EPS Generation')
p1 = bar(ind, data01, width, color='#CCCCFF')
p2 = bar(ind+width, data02, width, color='#3399FF')
xticks(ind+width, ('1', '2', '3', '4') )
xlim(-width,len(ind))
legend( (p1[0], p2[0]), ('data01', 'data02'), loc='upper right', shadow=False)
pylab.savefig('test.eps')

I get a nice EPS file which looks good in my final PDF. Also, running ps2pdf
and pdffonts shows that all the fonts are properly embedded in the eps file:

======================
$ ps2pdf test.eps
$ pdffonts test.pdf
name type emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------
NBOBDW+BitstreamVeraSans-Roman TrueType yes yes no 8 0

So as one would expect, the plots look good in the final PDF when zooming in
and out because all the fonts are there. On the other hand, if I uncomment
the "rc('text', usetex=True)" line in the script so that Latex is used for
the fonts, I get the following when converting the resulting EPS file to PDF:

=======================
$ ps2pdf test.eps
$ pdffonts test.pdf
name type emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------

=======================

As you can see, there's no font embedding in this case and the image looks bad
when previewed in either Ghotsview (eps) or in PDF. Does anyone know if it's
possible to get Matplotlib + Latex font embedding to work?

Regards,
Stephan

Hello,

I've been using Matplotlib to generate postscript (eps) graphics which I
import into my latex documents. I tried using Latex to typeset
mathematical symbols on my plots using the steps described here:

http://www.scipy.org/Cookbook/Matplotlib/UsingTex

The problem (I think) is that the eps files are genrated using dvipng,
which results in ugly figures in the final PDF output. Is there a way to
get Matplotlib to *not* use dvipng as the backend?

matplotlib only uses dvipng to render the text on screen in the plot window.
Postscript file generation does not use dvipng. We paste in some tags and use
the latex package psfrag to replace the tags with the text.

On the other hand, if I
uncomment the "rc('text', usetex=True)" line in the script so that Latex is
used for the fonts, I get the following when converting the resulting EPS
file to PDF:

=======================
$ ps2pdf test.eps
$ pdffonts test.pdf
name type emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------

=======================

As you can see, there's no font embedding in this case and the image looks
bad when previewed in either Ghotsview (eps) or in PDF. Does anyone know
if it's possible to get Matplotlib + Latex font embedding to work?

Unfortunately, psfrag produces postscript that can not be embedded in another
file, so we have to distill the output. By default, the ghostscript distiller
is used, but if you have pdftops (available with xpdf), you can set the
ps.usedistiller option to xpdf and the fonts will be embedded. This is
discussed at http://www.scipy.org/Cookbook/Matplotlib/UsingTex.

Darren

···

On Thursday 07 June 2007 10:06:03 pm Stephan Bourduas wrote:

--
Darren S. Dale, Ph.D.
dd55@...163...

You're right; using 'xpdf' solved my problem. I didn't notice the (last)
sentence which mentions using xpdf and poppler as a backend. Thanks for
pointing it out.

Stephan

···

On June 8, 2007, Darren Dale wrote:

Unfortunately, psfrag produces postscript that can not be embedded in
another file, so we have to distill the output. By default, the ghostscript
distiller is used, but if you have pdftops (available with xpdf), you can
set the ps.usedistiller option to xpdf and the fonts will be embedded. This
is discussed at http://www.scipy.org/Cookbook/Matplotlib/UsingTex.