latex labels on saved plots

Jordan Atlas <jca33@...163...> writes:

I'm having trouble saving eps or pdf versions of plots that have
TeX labels using matplotlib.

Which version of matplotlib are you using? The error message you quote
for the pdf backend shows a line 1085 in get_canvas_width_height, which
is impossible both in the latest released version 0.90.1 and in current
svn. I vaguely remember there being a bug like that quite some time ago.

In any case, no released version of matplotlib supports using TeX with
the pdf backend. Do you mean the (TeX-like) mathtext format parsed by
matplotlib? In current svn there is some support for TeX with the pdf
backend, but it has not (AFAIK) been tested on Windows.

I saw an older thread
(http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg03953.html
) that seems to address similar issues, but I don't understand the
solution (using XPDF distiller).

Gmane mangles the URL (to protect email addresses) so I can't read the
message you cite, but using the XPDF distiller means setting
ps.usedistiller to xpdf in your matplotlibrc file. You will need to have
ps2pdf (from ghostscript) and pdftops (from xpdf or poppler) installed.

···

--
Jouni K. Sepp�nen
http://www.iki.fi/jks

Jouni,

Which version of matplotlib are you using? The error message you quote
for the pdf backend shows a line 1085 in get_canvas_width_height, which
is impossible both in the latest released version 0.90.1 and in current
svn. I vaguely remember there being a bug like that quite some time ago.

I apologize for the missing information. I was using matplotlib 0.90.0 with python 2.4, and just upgraded to matplotlib 0.90.1 after reading your message. Also, I'm doing this all on winXP.

Now, when I try to save a PDF (with the newer version of matplotlib), I get the error:

  File "C:\Python24\Lib\site-packages\matplotlib\pylab.py", line 796, in savefig
    return fig.savefig(*args, **kwargs)
  File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 759, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 187, in print_figu
re
    agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line 497, in print_figure

    printfunc(filename, dpi, facecolor, edgecolor, orientation, **kwargs)
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_pdf.py", line 1393, in print_figur
e
    self.figure.draw(renderer)
  File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 601, in draw
    for a in self.axes: a.draw(renderer)
  File "C:\Python24\Lib\site-packages\matplotlib\axes.py", line 1286, in draw
    a.draw(renderer)
  File "C:\Python24\Lib\site-packages\matplotlib\axis.py", line 601, in draw
    tick.draw(renderer)
  File "C:\Python24\Lib\site-packages\matplotlib\axis.py", line 176, in draw
    if self.label1On: self.label1.draw(renderer)
  File "C:\Python24\Lib\site-packages\matplotlib\text.py", line 911, in draw
    Text.draw(self, renderer)
  File "C:\Python24\Lib\site-packages\matplotlib\text.py", line 420, in draw
    self._fontproperties, angle)
  File "C:\Python24\Lib\site-packages\matplotlib\backend_bases.py", line 383, in draw_tex
    raise NotImplementedError
NotImplementedError

I get the same error as in my original post when trying to save an EPS:

  File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 759, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 187, in print_figu
re
    agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line 497, in print_figure

    printfunc(filename, dpi, facecolor, edgecolor, orientation, **kwargs)
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_ps.py", line 1011, in print_figure

    orientation, papertype)
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_ps.py", line 1247, in _print_figur
e_tex
    else: gs_distill(tmpfile, ext=='.eps', ptype=papertype, bbox=bbox)
  File "C:\Python24\Lib\site-packages\matplotlib\backends\backend_ps.py", line 1366, in gs_distill
    if exit_status: raise RuntimeError('ghostscript was not able to process \
RuntimeError: ghostscript was not able to process your image.
Here is the full report generated by ghostscript:

In any case, no released version of matplotlib supports using TeX with
the pdf backend. Do you mean the (TeX-like) mathtext format parsed by
matplotlib? In current svn there is some support for TeX with the pdf
backend, but it has not (AFAIK) been tested on Windows.

I guess I mean TeX-like mathtext format parsed by matplotlib. For example, I'm using things like this:

rc('text', usetex=True) Plotting.xlabel(r'\textbf{Time (s)}', fontsize=16)

Gmane mangles the URL (to protect email addresses) so I can't read the
message you cite, but using the XPDF distiller means setting
ps.usedistiller to xpdf in your matplotlibrc file. You will need to have
ps2pdf (from ghostscript) and pdftops (from xpdf or poppler) installed.

I will look into this immediately.

Thank you,

--Jordan