# noob questions

Hi, I’m fairly new to using matplotlib
having just stopped using Matlab and started using Python.

I have two questions about matplotlib.

1. It’s pretty easy to include
text on a graph, but are LaTex strings supported? That is, I want to
write something like this on my plot: ‘\Phi_0 = blah…’.
When passing a LaTex command as part of text string to be written on a plot in MatLab,
it interprets this and displays the (in this case) Greek symbol. Any
suggestions on how this is or should be done with matplotlib?

2. How do I format how tick mark labels
are displayed? I have a plot whose x-axis runs from 0 to 8.5e-5. But
the tick mark labels are 0,0.00001,0.00002,0.00003… This is rather
unsightly, but I haven’t found a way to specify the format of these
numbers.

thanks for any help,

trevis

···

Trevis Crane

Postdoctoral Research Assoc.

Department of Physics

University of Ilinois

1110 W. Green St.

Urbana, IL 61801

p: 217-244-8652

f: 217-244-2278

e: tcrane@…1315…

I have two questions about matplotlib.

1) It's pretty easy to include text on a graph, but are LaTex strings
supported? That is, I want to write something like this on my plot:
'\Phi_0 = blah...'. When passing a LaTex command as part of text string
to be written on a plot in MatLab, it interprets this and displays the
(in this case) Greek symbol. Any suggestions on how this is or should
be done with matplotlib?

matplotlib supports mathtext strings, like r'$\Phi_0 = e^{i\pi}$'. Currently,
if you want to mix mathmode and regular mode, r'for example: $\Phi_0 = e^{i\pi}$', you need to enable usetex in your matplotlibrc file. usetex
requires latex, ghostscript, dvipng to be properly installed, see
http://www.scipy.org/Cookbook/Matplotlib/UsingTex for more details.

2) How do I format how tick mark labels are displayed? I have a plot
whose x-axis runs from 0 to 8.5e-5. But the tick mark labels are
0,0.00001,0.00002,0.00003... This is rather unsightly, but I haven't
found a way to specify the format of these numbers.

That's a new problem. Eric, it looks like some of your recent changes to
ticker.py had some unintended side-effects. Do you have time to look into it?

Darren

···

On Wednesday 23 May 2007 11:17:14 am Trevis Crane wrote:

Look into the arguments of the xticks function. I do things like

tickvals = arange(5.998,6.0025,0.0005);
ticklabs = map(lambda val:"%.4f"%val, tickvals);
ticklabs[0::2] = map(lambda val:"%.3f"%val, tickvals[0::2]);
xticks(tickvals,ticklabs);

to customize.
JTW

···

On Wed, 23 May 2007, Trevis Crane wrote:

2) How do I format how tick mark labels are displayed? I have a plot
whose x-axis runs from 0 to 8.5e-5. But the tick mark labels are
0,0.00001,0.00002,0.00003... This is rather unsightly, but I haven't
found a way to specify the format of these numbers.

Hi Trevis,

1) It's pretty easy to include text on a graph, but are LaTex strings
supported? That is, I want to write something like this on my plot:
'\Phi_0 = blah...'. When passing a LaTex command as part of text string
to be written on a plot in MatLab, it interprets this and displays the
(in this case) Greek symbol. Any suggestions on how this is or should
be done with matplotlib?

See the chapter on mathtext on page 32 in the user guide:

http://matplotlib.sourceforge.net/users_guide_0.90.0.pdf

2) How do I format how tick mark labels are displayed? I have a plot
whose x-axis runs from 0 to 8.5e-5. But the tick mark labels are
0,0.00001,0.00002,0.00003... This is rather unsightly, but I haven't
found a way to specify the format of these numbers.

That is described on page 52 in the user guide (see listing 6.1 for an
example).

Hope this helps.

Cheers,
Jesper

···

On Wednesday 23 May 2007 17:17, Trevis Crane wrote: