upgrades to postscript and usetex

This morning I finished some changes to mpl's postscript and usetex options.

1) In matpltolibrc, ps.usedistiller should now be set to None, ghostscript, or
xpdf. If you had usedistiller = True, it needs to be changed to ghostscript.
The xpdf option is preferable where available, producing publication quality
output and small file sizes. It requires ghostscript, xpdf and ps2eps.

2) It used to be that for the usetex option, backend_ps created a bunch of
temporary files in the current directory. These steps have been moved to the
os's temp directory.

3) (usetex = True) and (usedistiller = ghostscript or xpdf) all require
external dependencies. When these rc-options are validated, these deps are
checked and an error is raised when something is missing.

These changes are all available in cvs. Testing and comments appreciated.

Darren

Darren Dale <dd55@...143...> writes:

This morning I finished some changes to mpl's postscript and usetex options.

These changes are all available in cvs. Testing and comments appreciated.

In 0.86, which I don't think incorporates your changes[1], there is a
small problem with the text size.

The text in the postscript version is longer than in the tkagg
version, and also is not centred.

If the label is quite long, it is quite clear that in the eps version,
the text for the axis labels is not centred. I've attached a modified
version of tex_demo.py to demonstrate the effect.

Chris

[1] I did try replacing backend_ps.py with the cvs version, but it
didn't work - and I don't have time at the moment to investigate
further - probably I need to update other files too.

#!/usr/bin/env python
"""
You can use TeX to render all of your matplotlib text if the rc
parameter text.usetex is set. This works currently on the agg and ps
backends, and requires that you have tex and the other dependencies
described at http://matplotlib.sf.net/matplotlib.texmanager.html
properly installed on your system. The first time you run a script
you will see a lot of output from tex and associated tools. The next
time, the run may be silent, as a lot of the information is cached in
~/.tex.cache

"""
from matplotlib import rc
from matplotlib.numerix import arange, cos, pi
from pylab import figure, axes, plot, xlabel, ylabel, title, \
     grid, savefig, show

rc('text', usetex=True)
rc('ps', usedistiller=False)
figure(1)
ax = axes([0.1, 0.1, 0.8, 0.7])
t = arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2
plot(t, s)

xlabel(r'\bf{time (s) a realy long title that is not centered}')
ylabel(r'\it{voltage (mV) not centered}',fontsize=25)
title(r"\TeX\ is Number \\displaystyle\\sum\_\{n=1\}^\\infty\\frac\{\-e^\{i\\pi\}\}\{2^n\}!",
      fontsize=25, color='r')
grid(True)
savefig('tex_demo.eps')

show()

For some reason, the kerning is messed up in the eps file. I tried using the
pslatex font package (set in matplotlibrc) and the kerning there is ok. It
still is not perfectly centered, and I dont know why that might be.

···

On Wednesday 11 January 2006 11:09, Chris Walker wrote:

Darren Dale <dd55@...143...> writes:
> This morning I finished some changes to mpl's postscript and usetex
> options.
>
>
>
> These changes are all available in cvs. Testing and comments appreciated.

In 0.86, which I don't think incorporates your changes[1], there is a
small problem with the text size.

The text in the postscript version is longer than in the tkagg
version, and also is not centred.

I get better results with \textbf than with \bf, but still not perfect.

There are a lot of places this can get screwed up: dvipng, PSFrag, MPL... I
would like to eventually do the tex support the right way, possibly using the
PyX package, but I am still waiting to hear if PyX will consider releasing
under the Python license.

Darren

···

On Wednesday 11 January 2006 12:21, Darren Dale wrote:

On Wednesday 11 January 2006 11:09, Chris Walker wrote:
> Darren Dale <dd55@...143...> writes:
> > This morning I finished some changes to mpl's postscript and usetex
> > options.
> >
> >
> >
> > These changes are all available in cvs. Testing and comments
> > appreciated.
>
> In 0.86, which I don't think incorporates your changes[1], there is a
> small problem with the text size.
>
> The text in the postscript version is longer than in the tkagg
> version, and also is not centred.

Darren Dale <dd55@...143...> writes:

> >
> > In 0.86, which I don't think incorporates your changes[1], there is a
> > small problem with the text size.
> >
> > The text in the postscript version is longer than in the tkagg
> > version, and also is not centred.

I get better results with \textbf than with \bf, but still not perfect.

There are a lot of places this can get screwed up: dvipng, PSFrag, MPL... I

When I looked at the code, it wasn't clear that the font used for
calculating the width was the same as the one that actually ended up
being used for printing. In addition, the bounding box was calculated
for 10pt text, and then a scale factor used to scale the text. Any
inaccuracy in the bounding box will carry through.

One solution would be to calculate the bounding box for the text at
the appropriate size - this could have the additional advantage that
12pt fonts would be used for 12pt text, rather than 10 pt scaled by a
factor of 1.2. I'm sure I've read that TeX positions text slightly
differently in the two cases (though any advantage would be lost if
you end up scaling the eps).

would like to eventually do the tex support the right way, possibly using the> PyX package, but I am still waiting to hear if PyX will consider releasing
under the Python license.

Good luck.

Chris

···

On Wednesday 11 January 2006 12:21, Darren Dale wrote:
> On Wednesday 11 January 2006 11:09, Chris Walker wrote: