Remove toolbar item in bokeh python

落爺英雄遲暮 提交于 2021-01-29 07:11:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!