LateX typeset colorbar annotations

Using format strings like %e or %g I can have “scientific notation”

What is the simplest way to format the number in LaTeX format, i.e. 1\times10^{9} (1\times10^{9} instead of 1.0e+09) automatically in places where numbers are displayed Paraview, for example in colorbar level annotations?

2 Likes

You can embed latex expressions inside $$ like you would for inline equations in LaTeX.

However, that applies only to custom annotations, not the automatically generated tick labels. There isn’t currently a way to use LaTeX expression formatting for the tick labels.

I see. I was more interested in using this format in auto generated labels.

Something similar to this on the auto generated labels will also do the job for me

def latex_float(f):
    float_str = "{0:.2g}".format(f)
    if "e" in float_str:
        base, exponent = float_str.split("e")
        return r"${0} \times 10^{{{1}}}$".format(base, int(exponent))
    else:
        return float_str

Testing:

>>> latex_float(-1.5e-9)
'$-1.5 \\times 10^{-9}$'
>>> latex_float(1.e-9)
'$1 \\times 10^{-9}$'
>>> latex_float(1.e9)
'$1 \\times 10^{9}$'
>>> latex_float(1.e+09)
'$1 \\times 10^{9}$'