Adding two BoxZoomTools (with different settings) to the same toolbar

I need to have one BoxZoomTool that is restricted to zoom only in the width. But I also need one that can zoom in the other direction(s). (Ideally, I’d have one tool with some way of doing both actions.)

However, it doesn’t seem possible for me to add two BoxZoomTools to the same toolbar. If I do, only one appears and doesn’t seem to work.
Is this because of how the toolbar is made? Or is there a way to do this?

Thanks

You can add multiple, telling them apart will be the issue.

Configuring plot tools — Bokeh 2.4.3 Documentation

from bokeh.plotting import figure, show
from bokeh.models import BoxZoomTool, BoxSelectTool

plot = figure(width=400, height=400, tools='reset')
plot.circle([1, 2, 3], [1, 2, 3], size=20)

plot.add_tools(BoxZoomTool())
plot.add_tools(BoxZoomTool(dimensions='width'))
plot.add_tools(BoxZoomTool(dimensions='height'))

show(plot)
1 Like

Nice. You could probably use the “description” arg to tell them apart → it’s how I handle multiple hovertools :smiley:

1 Like

Ok, thanks for the example. I figured out what is going wrong. This doesn’t seem to work with merge_tools=True in gridplot (which is also the default value).

For example:

from bokeh.plotting import figure, show
from bokeh.models import BoxZoomTool
from bokeh.layouts import gridplot

plot = figure(width=400, height=400, tools='reset')
plot.circle([1, 2, 3], [1, 2, 3], size=20)

plot.add_tools(BoxZoomTool())
plot.add_tools(BoxZoomTool(dimensions='width'))
plot.add_tools(BoxZoomTool(dimensions='height'))

plot2 = figure(width=400, height=400, tools='reset')
plot2.circle([3, 2, 1], [1, 2, 3], size=20)

plot2.add_tools(BoxZoomTool())
plot2.add_tools(BoxZoomTool(dimensions='width'))
plot2.add_tools(BoxZoomTool(dimensions='height'))

show(gridplot([[plot], [plot2]],sizing_mode="stretch_both",merge_tools=True))

Note that if you set merge_tool=False, it works again.
Would this constitute a bug?

Ok, apparently this is an older bug which is supposed to be fixed in bokeh 3.0-dev.6.