Abbreviated notation for small numbers in axis tick formatter?

Hi Community,

I’m looking to display some small numbers (on the order of 10^-6), and it seems natural to format the y-axis tick labels with abbreviated notations.

E.g., 5e-6 = 0.000005 should be displayed as 5u, or better:

5\mu

However, I have not found a way to achieve this with NumericalTickFormatter, where the option a does not abbreviate below the decimal point. E.g.,

NumeralTickFormatter(format="0.00 a")


would give me 0.00.

Is there a way I can do this with Bokeh?

Skeleton code:

from bokeh.models.formatters import NumeralTickFormatter
from bokeh.plotting import figure, output_file, show
p = figure(plot_width=400, plot_height=400)
p.circle([1,2,3,4,5], [x*10**(-6) for x in [2,5,8,2,7]], size=10)
p.yaxis[0].formatter = NumeralTickFormatter(format="0.00a")
show(p)


@Pill-GZ That seems rather specialized, I don’t think any of the built-in formatters will do what you are asking, unless I am misunderstanding. Your best bet is probably to use a FuncTickFormatter which allows you to specify a few lines of JavaScript to arbitrarily format the tick value however you need. There’s a full example here:

1 Like

Hi @Bryan,

Thanks!
I will play with FuncTickFormatter as you suggested.

It is specialized indeed. I can imagine some users will be interested in plotting very small numbers (e.g. p-values) below the decimal point. It would be wonderful to be able to use a fomatter option for axis tick labels like

5\mu

or

5\times10^{-6}.

It’s a bit unclear what you mean by the last example in scientific notation. If you only want scientific notation, then the standard BasicTickFormatter will already render ticks that way e.g. as 5e-6

I was looking for axis labels that looks like the latex renderings above, with multiplication sign and superscripts for exponents.

“5e-6” isn’t exactly publication quality tick label. And there does not seem to be a good native alternative in Bokeh.

I did not use the term “scientific notation” in this post since that is how Bokeh refers to format such as “5e-6”. I do not want “scientific notation” in the Bokeh sense

Just for reference, this is how Plotly chooses to label small numbers:

Tick values below 0.001 are labeled with micro (\mu) and values below 0.000001 are labeled with nano (n).

Well, you can definitely do that with FuncTickFormatter in ~5-6 lines of JS code for now. (No one has ever asked for formatting like this before, but you can make a GitHub Issue to request it if you like)