Dollar sign in TeX plot label

I am having trouble creating a plot using TeX which has a $ sign in
one of the axis labels. If I run:

import matplotlib

matplotlib.rc('font', **{'family': 'serif', 'serif': ['Computer Modern Roman']})
matplotlib.rc('text', usetex=True)

import pylab

pylab.figure()
pylab.plot([0.0, 1.0])
pylab.ylabel("Profit (\$)")
pylab.savefig('/tmp/fig.pdf')

I get the error:

Traceback (most recent call last):
  File "/home/rwl/python/aes/Pylon/examples/pyreto/thesis/plot_tex.py",
line 12, in <module>
    pylab.savefig('/tmp/fig.pdf')
  File "/usr/lib/pymodules/python2.5/matplotlib/pyplot.py", line 356, in savefig
    return fig.savefig(*args, **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/figure.py", line 1032,
in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/backend_bases.py",
line 1476, in print_figure
    **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/backend_bases.py",
line 1334, in print_pdf
    return pdf.print_pdf(*args, **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/backends/backend_pdf.py",
line 2031, in print_pdf
    self.figure.draw(renderer)
  File "/usr/lib/pymodules/python2.5/matplotlib/artist.py", line 46,
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/figure.py", line 773, in draw
    for a in self.axes: a.draw(renderer)
  File "/usr/lib/pymodules/python2.5/matplotlib/artist.py", line 46,
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/axes.py", line 1735, in draw
    a.draw(renderer)
  File "/usr/lib/pymodules/python2.5/matplotlib/artist.py", line 46,
in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.5/matplotlib/axis.py", line 757, in draw
    self.label.draw(renderer)
  File "/usr/lib/pymodules/python2.5/matplotlib/text.py", line 556, in draw
    self._fontproperties, angle)
  File "/usr/lib/pymodules/python2.5/matplotlib/backends/backend_pdf.py",
line 1437, in draw_tex
    psfont = self.tex_font_mapping(dvifont.texname)
  File "/usr/lib/pymodules/python2.5/matplotlib/backends/backend_pdf.py",
line 1269, in tex_font_mapping
    return self.tex_font_map[texfont]
  File "/usr/lib/pymodules/python2.5/matplotlib/dviread.py", line 673,
in __getitem__
    result = self._font[texname]
KeyError: 'tcrm1200'

I am using Debian/unstable and have the latest texlive installed. Can
anyone tell me what the problem might be?

Richard

plot_tex.py (260 Bytes)

Try:

pylab.ylabel(r"Profit (\$)")

···

On Mon, Aug 2, 2010 at 10:15 AM, Richard Lincoln <r.w.lincoln@...287...> wrote:

I am having trouble creating a plot using TeX which has a $ sign in
one of the axis labels. If I run:

import matplotlib

matplotlib.rc('font', **{'family': 'serif', 'serif': ['Computer Modern Roman']})
matplotlib.rc('text', usetex=True)

import pylab

pylab.figure()
pylab.plot([0.0, 1.0])
pylab.ylabel("Profit (\$)")
pylab.savefig('/tmp/fig.pdf')

I get the error:

No luck. Nor with:

matplotlib.rc('text.latex', unicode=True)
pylab.ylabel(u"Profit (\$)")

···

On 2 August 2010 15:19, Darren Dale <dsdale24@...287...> wrote:

On Mon, Aug 2, 2010 at 10:15 AM, Richard Lincoln <r.w.lincoln@...287...> wrote:

I am having trouble creating a plot using TeX which has a $ sign in
one of the axis labels. If I run:

import matplotlib

matplotlib.rc('font', **{'family': 'serif', 'serif': ['Computer Modern Roman']})
matplotlib.rc('text', usetex=True)

import pylab

pylab.figure()
pylab.plot([0.0, 1.0])
pylab.ylabel("Profit (\$)")
pylab.savefig('/tmp/fig.pdf')

I get the error:

Try:

pylab.ylabel(r"Profit (\$)")

Hmmm, if I comment out the .savefig() and use the show(), I get no errors. But I get the same key error if I try to save it as a pdf. However, if I save it as a png, I get no problems.

Maybe it is a problem with the pdf backend?

Ben Root

···

On Mon, Aug 2, 2010 at 9:29 AM, Richard Lincoln <r.w.lincoln@…287…> wrote:

On 2 August 2010 15:19, Darren Dale <dsdale24@…287…> wrote:

On Mon, Aug 2, 2010 at 10:15 AM, Richard Lincoln <r.w.lincoln@…287…> wrote:

I am having trouble creating a plot using TeX which has a $ sign in

one of the axis labels. If I run:

import matplotlib

matplotlib.rc(‘font’, **{‘family’: ‘serif’, ‘serif’: [‘Computer Modern Roman’]})

matplotlib.rc(‘text’, usetex=True)

import pylab

pylab.figure()

pylab.plot([0.0, 1.0])

pylab.ylabel(“Profit ($)”)

pylab.savefig(’/tmp/fig.pdf’)

I get the error:

Try:

pylab.ylabel(r"Profit ($)")

No luck. Nor with:

matplotlib.rc(‘text.latex’, unicode=True)

pylab.ylabel(u"Profit ($)")


The Palm PDK Hot Apps Program offers developers who use the

Plug-In Development Kit to bring their C/C++ apps to Palm for a share

of $1 Million in cash or HP Products. Visit us here for more details:

http://p.sf.net/sfu/dev2dev-palm


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

You could use

pylab.ylabel(r"Profit (\verb+$+)")

or use another font.

Eduardo

···

On 2 Aug 2010, at 15:50, Benjamin Root wrote:

Hmmm, if I comment out the .savefig() and use the show(), I get no errors. But I get the same key error if I try to save it as a pdf. However, if I save it as a png, I get no problems.

Maybe it is a problem with the pdf backend?

Ben Root

On Mon, Aug 2, 2010 at 9:29 AM, Richard Lincoln <r.w.lincoln@…287…> wrote:

On 2 August 2010 15:19, Darren Dale <dsdale24@…287…> wrote:

On Mon, Aug 2, 2010 at 10:15 AM, Richard Lincoln <r.w.lincoln@…287…> wrote:

I am having trouble creating a plot using TeX which has a $ sign in

one of the axis labels. If I run:

import matplotlib

matplotlib.rc(‘font’, **{‘family’: ‘serif’, ‘serif’: [‘Computer Modern Roman’]})

matplotlib.rc(‘text’, usetex=True)

import pylab

pylab.figure()

pylab.plot([0.0, 1.0])

pylab.ylabel(“Profit ($)”)

pylab.savefig(’/tmp/fig.pdf’)

I get the error:

Try:

pylab.ylabel(r"Profit ($)")

No luck. Nor with:

matplotlib.rc(‘text.latex’, unicode=True)

pylab.ylabel(u"Profit ($)")