只需设置toggleable
归因于False
。检查此示例,其中隐藏了悬停工具按钮:
from bokeh.models import HoverTool, ColumnDataSource, LassoSelectTool, PanTool
from bokeh.plotting import show, figure, curdoc
source = ColumnDataSource(dict(
x=[1, 2, 3, 4],
y=[5, 6, 7, 8]
))
p = figure(
width=400,
height=400,
tools='')
p.scatter(
x='x', y='y', source=source,
fill_alpha=1.0, line_alpha=1.0, line_color="grey",
size=6
)
pan = PanTool()
lasso = LassoSelectTool()
tooltips = '''
<b>X: </b> @{x} <br>
<b>Y: </b> @{y} <br>
'''
hover = HoverTool(
toggleable=False, # add this to all your hover tools
mode='mouse',
tooltips=tooltips,
)
tools = (
pan, lasso, hover
)
p.add_tools(*tools)
curdoc().add_root(p)
好吧,如果您只想使用一个按钮,那么您可能只使用一个悬停工具。该模型CustomJSHover https://bokeh.pydata.org/en/latest/docs/reference/models/tools.html#bokeh.models.tools.CustomJSHover可能对你有用。
作为解决方法,您还可以更新renderers https://bokeh.pydata.org/en/latest/docs/reference/models/tools.html#bokeh.models.tools.HoverTool.renderers每次悬停按下某个按钮或自定义工具的属性。