# Latex in Figures

Dear All,
I think the solution to my problem must be a one-liner, but I have
been unsuccessful.
I am trying to use latex formulas (nothing dramatically complicated)
inside a figure.
I suppose everything is working correctly on my system.
I tried running the example at:
http://www.scipy.org/Cookbook/Matplotlib/UsingTex
and it works fine.
But now have a look at this:

#! /usr/bin/env python

import scipy as s
import numpy as n
import pylab as p

x=s.linspace(0.,(2.*s.pi),100)
y=s.sin(x)

z=s.exp(-x)

#Now I create my figure

fig = p.figure()
axes = fig.gca()

axes.plot(x,y, "bo",label=(r"$sin(\tau)$"))
axes.plot(x,z,'--r',label=(r"$\rm{decay}exp(\tau)$"),linewidth=2.)
p.xlabel('This is $\tau$')
p.ylabel('$N_\infty(\tau)$')
axes.legend()
p.title('My test functions')
p.grid(True)
p.savefig("simple_test.pdf")

p.clf()

The point of the example figure is to try mixing latex formulas and text.
Obviously, the result is not satisfactory. If I use \sin for instance,
then I get an error message as that is not recognized.
I think the fix to this must be rather simple for someone
knowledgeable, but so far my attempts to get some decent mixed
latex/text output have been unsuccessful.
Can anyone help me with this simple example code?
Many thanks

Lorenzo

Hello Lorenzo,

maybe you don't really use Tex to build the labels and mathtext does not
support any Tex-functionality.
if you use:

···

------------------------------------
from matplotlib import rc
rc('text', usetex=True)
import pylab as p
------------------------------------
it should work. Alternatively you could modify your matplotlibrc directly.

best regards
Matthias

On Tuesday 18 March 2008 10:39, Lorenzo Isella wrote:

Dear All,
I think the solution to my problem must be a one-liner, but I have
been unsuccessful.
I am trying to use latex formulas (nothing dramatically complicated)
inside a figure.
I suppose everything is working correctly on my system.
I tried running the example at:
http://www.scipy.org/Cookbook/Matplotlib/UsingTex
and it works fine.
But now have a look at this:

#! /usr/bin/env python

import scipy as s
import numpy as n
import pylab as p

x=s.linspace(0.,(2.*s.pi),100)
y=s.sin(x)

z=s.exp(-x)

#Now I create my figure

fig = p.figure()
axes = fig.gca()

axes.plot(x,y, "bo",label=(r"$sin(\tau)$"))
axes.plot(x,z,'--r',label=(r"$\rm{decay}exp(\tau)$"),linewidth=2.)
p.xlabel('This is $\tau$')
p.ylabel('$N_\infty(\tau)$')
axes.legend()
p.title('My test functions')
p.grid(True)
p.savefig("simple_test.pdf")

p.clf()

The point of the example figure is to try mixing latex formulas and text.
Obviously, the result is not satisfactory. If I use \sin for instance,
then I get an error message as that is not recognized.
I think the fix to this must be rather simple for someone
knowledgeable, but so far my attempts to get some decent mixed
latex/text output have been unsuccessful.
Can anyone help me with this simple example code?
Many thanks

Lorenzo

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Mattias' suggestion is a good one if you have a full TeX environment installed.

Otherwise, it looks like you're using some features that are only available in 0.91.x (but not earlier versions), for example "\sin". If you can, try upgrading.

Cheers,
Mike

Lorenzo Isella wrote:

···

Dear All,
I think the solution to my problem must be a one-liner, but I have
been unsuccessful.
I am trying to use latex formulas (nothing dramatically complicated)
inside a figure.
I suppose everything is working correctly on my system.
I tried running the example at:
http://www.scipy.org/Cookbook/Matplotlib/UsingTex
and it works fine.
But now have a look at this:

#! /usr/bin/env python

import scipy as s
import numpy as n
import pylab as p

x=s.linspace(0.,(2.*s.pi),100)
y=s.sin(x)

z=s.exp(-x)

#Now I create my figure

fig = p.figure()
axes = fig.gca()

axes.plot(x,y, "bo",label=(r"$sin(\tau)$"))
axes.plot(x,z,'--r',label=(r"$\rm{decay}exp(\tau)$"),linewidth=2.)
p.xlabel('This is $\tau$')
p.ylabel('$N_\infty(\tau)$')
axes.legend()
p.title('My test functions')
p.grid(True)
p.savefig("simple_test.pdf")

p.clf()

The point of the example figure is to try mixing latex formulas and text.
Obviously, the result is not satisfactory. If I use \sin for instance,
then I get an error message as that is not recognized.
I think the fix to this must be rather simple for someone
knowledgeable, but so far my attempts to get some decent mixed
latex/text output have been unsuccessful.
Can anyone help me with this simple example code?
Many thanks

Lorenzo

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users