Problem using TeX formatting in labels

Hello,

I am getting an error when I try to use any TeX formatting in plot
labels. There is an example below. I don't know if its relevant, but
I can only use the "latex" command in my OSX terminal. If I try
"latex sample.tex" in an x11 window, x11 claims no knowledge of latex.

I have had to install two libraries and hunt down my kpathsea library,
and this still isn't working. Is there any easier way to achieve text
and math together in a label, such as "Text $\pi$" ? Thanks,

Adrian

In [1]: matplotlib.rc('text', usetex=True)

In [2]: plot(arange(3), arange(3));xlabel('Text')
sh: line 1: latex: command not found

···

---------------------------------------------------------------------------
exceptions.RuntimeError Traceback (most
recent call last)

/Users/adrian/Documents/Academic/Courses/Research/Cosmo/Code/<ipython console>

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/pylab.py
in plot(*args, **kwargs)
   3089 try:
   3090 ret = gca().plot(*args, **kwargs)
-> 3091 draw_if_interactive()
   3092 except:
   3093 hold(b)

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/IPython/genutils.py
in wrapper(*args, **kw)
    742 def wrapper(*args,**kw):
    743 wrapper.called = False
--> 744 out = func(*args,**kw)
    745 wrapper.called = True
    746 return out

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/backends/backend_tkagg.py
in draw_if_interactive()
     57 figManager = Gcf.get_active()
     58 if figManager is not None:
---> 59 figManager.show()
     60
     61

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/backends/backend_tkagg.py
in show(self)
    303 if sys.platform=='win32' : self.window.update()
    304 else:
--> 305 self.canvas.draw()
    306 self._shown = True
    307

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/backends/backend_tkagg.py
in draw(self)
    152
    153 def draw(self):
--> 154 FigureCanvasAgg.draw(self)
    155 tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
    156 self._master.update_idletasks()

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py
in draw(self)
    390
    391 renderer = self.get_renderer()
--> 392 self.figure.draw(renderer)
    393
    394 def get_renderer(self):

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/figure.py
in draw(self, renderer)
    542
    543 # render the axes
--> 544 for a in self.axes: a.draw(renderer)
    545
    546 # render the figure text

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axes.py
in draw(self, renderer, inframe)
   1070
   1071 for zorder, i, a in dsu:
-> 1072 a.draw(renderer)
   1073
   1074 self.transData.thaw() # release the lazy objects

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axis.py
in draw(self, renderer, *args, **kwargs)
    559 tick.set_label1(label)
    560 tick.set_label2(label)
--> 561 tick.draw(renderer)
    562 if tick.label1On and tick.label1.get_visible():
    563 extent = tick.label1.get_window_extent(renderer)

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axis.py
in draw(self, renderer)
    159 if self.tick2On: self.tick2line.draw(renderer)
    160
--> 161 if self.label1On: self.label1.draw(renderer)
    162 if self.label2On: self.label2.draw(renderer)
    163

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/text.py
in draw(self, renderer)
    836 def draw(self, renderer):
    837 self.update_coords(renderer)
--> 838 Text.draw(self, renderer)
    839 if self.get_dashlength() > 0.0:
    840 self.dashline.draw(renderer)

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/text.py
in draw(self, renderer)
    338
    339 return
--> 340 bbox, info = self._get_layout(renderer)
    341
    342 if ismath=='TeX':

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/text.py
in _get_layout(self, renderer)
    185 heightt += 3 # 3 pixel pad
    186 for line in lines:
--> 187 w,h = renderer.get_text_width_height(
    188 line, self._fontproperties, ismath=self.is_math_text())
    189

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py
in get_text_width_height(self, s, prop, ismath, rgb)
    238 size = prop.get_size_in_points()
    239 texmanager = self.get_texmanager()
--> 240 Z = texmanager.get_rgba(s, size, self.dpi.get(), rgb)
    241 m,n,tmp = Z.shape
    242 return n,m

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/texmanager.py
in get_rgba(self, tex, fontsize, dpi, rgb)
    327 if Z is None:
    328 # force=True to skip cacheing while debugging
--> 329 pngfile = self.make_png(tex, fontsize, dpi, force=False)
    330 X = readpng(os.path.join(self.texcache, pngfile))
    331

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/texmanager.py
in make_png(self, tex, fontsize, dpi, force)
    242 # see get_rgba for a discussion of the background
    243 if force or not os.path.exists(pngfile):
--> 244 dvifile = self.make_dvi(tex, fontsize)
    245 outfile = basefile+'.output'
    246 command = self.get_shell_cmd('cd "%s"' % self.texcache,

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/texmanager.py
in make_dvi(self, tex, fontsize, force)
    223 fh = file(outfile)
    224 if exit_status:
--> 225 raise RuntimeError('LaTeX was not able to
process the flowing \
    226 string:\n%s\nHere is the full report generated by LaTeX:
\n\n'% tex + fh.read())
    227 else: verbose.report(fh.read(), 'debug')

RuntimeError: LaTeX was not able to process the flowing string:
$0.0$
Here is the full report generated by LaTeX:

Hi Adrian,

I am getting an error when I try to use any TeX formatting in plot
labels. There is an example below. I don't know if its relevant, but
I can only use the "latex" command in my OSX terminal. If I try
"latex sample.tex" in an x11 window, x11 claims no knowledge of latex.

See http://www.scipy.org/Cookbook/Matplotlib/UsingTex. You need to make sure
that latex, ghostscript and dvipng are all on your PATH.

I have had to install two libraries and hunt down my kpathsea library,
and this still isn't working. Is there any easier way to achieve text
and math together in a label, such as "Text \\pi" ? Thanks,

Usetex is currently the only way to render text that mixes regular text with
mathtext. Also note, you should use raw strings: r"Text \\pi", not "Text
\\pi"

Darren

···

On Thursday 05 April 2007 09:01:55 am Adrian Down wrote: