Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Because Sage decimal numbers (elements of RR) do not have a proper format, I would recommend to transform them into a Python float before sending them to a string. In your case, you could use:

label_fmt = lambda x: r"$10^{{{0:.3g}}}$".format(float(log(x, 10)))

It yields

sage: contours=[1e-25,1e-24,1e-23,1e-22,1e-21,1e-20,1e-19]
sage: [label_fmt(c) for c in contours]

NB: of course, 0 deserves a special treatment and has been excluded from the above list.