Why is there two wheel zoom tools on the tool bar in my figure?

I want to have wheel zoom to be active on start, and zoom_on_axis to be false. However, why is ther two wheel zoom tools on the tool bar?

from bokeh.plotting import figure, show
from bokeh.models.tools import WheelZoomTool

p = figure()
p.image_url([‘https://static.bokeh.org/logos/logo.png’],0,0,1,1)
wheel_zoom_tool = WheelZoomTool(zoom_on_axis=False)
p.add_tools(wheel_zoom_tool)
p.toolbar.active_scroll = wheel_zoom_tool
show(p)

Hi @thisuser,

The default toolbar already has one wheel zoom on it, so with your p.add_tools line, you’re adding a second one.

You could remove that line, and then to set the wheel zoom as the active scroll tool, use:
p.toolbar.active_scroll = p.toolbar.tools[1]

(To figure out that it was tool 1 in the list of existing tools, i ran print(p.toolbar.tools) to take a look at the order of items in the toolbar.)

Thanks for your reply, but how can I set zoom_on_axis to be false, if that line is removed?

Try:
p.toolbar.tools[1].zoom_on_axis = False

Just noting that, in principle, the wheel zoom tool might be in some other location in the .tools list besides index 1. A generic way of querying for all the wheel zoom tools on a plot is:

In [6]: p.select(WheelZoomTool)
Out[6]: [WheelZoomTool(id='1019', ...)]

Or if you are sure there is only one of them:

In [7]: p.select_one(WheelZoomTool)
Out[7]: WheelZoomTool(id='1019', ...)
1 Like