Skip to content Skip to sidebar Skip to footer

Remove Toolbar Item In Bokeh Python

To add a toolbar item, we do plot.add_tools(tool) What would be the opposite of this, where i want to remove a particular tool which I have reference to ?

Solution 1:

The Toolbar object of the plot can be used to remove the tool -

from bokeh.plotting import figure, output_file, show, output_notebook

output_notebook()

# create a new plot with the toolbar below
p = figure(plot_width=400, plot_height=400,
           title=None, toolbar_location="below")

p.circle([1, 2, 3, 4, 5], [2, 5, 8, 2, 7], size=10)

show(p)

This will generate a chart with 6 tools in toolbar.

enter image description here

Suppose, WheelZoomTool needs to be removed. The Toolbar object of plot will have a list of tools, and this tool can be deleted from there -

import bokeh
for tool in p.toolbar.tools:
    if isinstance(tool, bokeh.models.tools.WheelZoomTool):
        p.toolbar.tools.remove(tool)
show(p)

WheelZoomTool is gone from output

enter image description here


Post a Comment for "Remove Toolbar Item In Bokeh Python"