How do I create extra horizontal grid lines (@ say 1,2,5,10) for a Log Y axis

Standard plots seem to only have horizontal grid lines at multiples of 10 by default (base 10 log)
I want to have extra lines to aid in eyeballing the non linear nature of the data - perhaps say 1,2,5,10,20,50,100… etc.
Wanting this for the grid lines on the plot area - not the Y axis tick-marks.
I cant seem to locate the right area to be looking :slight_smile:
Can anyone point me in the right direction (assuming its possible :grin:)

I think the proper way to do this is to assign a FixedTicker to the ticker property on the grid object governing your y axis:

from bokeh.models import FixedTicker
from bokeh.plotting import figure, show

f= figure()
#the figure instance has a grid property, 
#which stores a two item list containing the grid instances governing the x and y axes respectively. 
#Each grid instance has a ticker property that we can assign a FixedTicker instance to, to explicitly set the grid line values on that axis 
f.grid[1].ticker = FixedTicker(ticks=[1,10,20,50,100])

Just noting, that as a convenience, the fixed ticker creation can be expressed more simply as:

f.ygrid.ticker = [1, 10, 20, 50, 100]

That will automatically create a FixedTicker and assign it to all available y-grids (there’s only the one in this case).

But all that said, you should also be able to configure the mantissas property of the existing log ticker to add more “nice” numbers for ticks.

1 Like

Thankyou both for help & greater understanding!
Was able to create desired plot by drawing in lines & specifying scale as required.
Curious that the NumeralTickFormatter uses lower case m for 1,000,000 (Mega) which is normally 0.001(milli) ?

Code that constructs basic version of what I was after (might help others as a base)

from bokeh.models import FixedTicker, NumeralTickFormatter
from bokeh.plotting import figure, show

f= figure(y_axis_type="log", y_range=[0.95*(10**0), 1.05*(10**5)], x_range=[0,6])


#draw power of 10 lines
for xx in range(0,7):
    f.line(x=[0,6],y=[10**xx,10**xx], line_color = 'black', line_width = 2)
# draw in-between lines (2 & 5)
f.ygrid.ticker = [2, 5, 20, 50, 200, 500, 2000, 5000, 20000, 50000, 200000, 500000]
f.ygrid.grid_line_color = "red"
f.ygrid.grid_line_alpha = 0.5
f.ygrid.grid_line_width = 1

#set labels for horizontal grid lines. 1 - 100k
f.yaxis.ticker = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000]
f.yaxis[0].formatter = NumeralTickFormatter(format="0 a")

1 Like

@watarat NumeralTickFormatter is actually just a very thin wrapper around the third-party numbro.js library, and Bokeh simply passes on the format strings as-is. You’d have to ask the authors of that library why they chose the format specifications that they did.

I see that they format 10^9 as “b”
Thus I guess they are thinking m = million, b = billion.

Ahh yes - a little poking around in their ‘language’ specification gives an example (snip below)
Thanks - interesting :grinning:

    abbreviations: {
        thousand: "k",
        million: "m",
        billion: "b",
        trillion: "t"
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.