问题
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 ?
回答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.
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
来源:https://stackoverflow.com/questions/63526003/remove-toolbar-item-in-bokeh-python