Formatting numbers with exponent with matplotlib

Hello folks.
I am trying to teach pylab to use latex to write numbers with an
exponent in the plot legend.
So far my plot labels are formatted with scientific notation, where
I use the format operate:

import pylab
ra_list,b = data
pylab.plot(ra_list,b, label='Ra = ' + "{0:4.2e}".format(ra_list[i]))
pylab.legend()
pylab.show()

What I ultimately want is that the exponent shows up as an exponent,
a la LaTeX style in the legend: $\mathrm{Ra} = 10^6$.

Does anybody know of a way how to do this with pylab?
Cheers, Ralph

I suggest having a look at the ScalarFormatter classer in ticker.py.
The feature you are looking for has already been implemented there.

Darren

ยทยทยท

On Mon, May 17, 2010 at 6:04 AM, Ralph Kube <ralphkube@...982...> wrote:

Hello folks.
I am trying to teach pylab to use latex to write numbers with an
exponent in the plot legend.
So far my plot labels are formatted with scientific notation, where
I use the format operate:

import pylab
ra_list,b = data
pylab.plot(ra_list,b, label='Ra = ' + "{0:4.2e}".format(ra_list[i]))
pylab.legend()
pylab.show()

What I ultimately want is that the exponent shows up as an exponent,
a la LaTeX style in the legend: \\mathrm\{Ra\} = 10^6.

Does anybody know of a way how to do this with pylab?