如何添加多个悬停工具而不在工具栏中显示多个图标?

2023-12-21

遵循示例here https://github.com/bokeh/bokeh/blob/16e87ed63ca1aecaa42e93293f32d936685dcd3e/sphinx/source/docs/user_guide/examples/categorical_bar_stacked_hover.py我已向堆积条形图添加了多个工具提示。我还希望在绘图上方的工具栏中提供其他工具,但是当使用示例中的过程创建多个悬停工具时,它会在工具栏中创建多个图标,使其看起来像这样混乱:

有没有办法添加多个悬停工具,并使工具栏与其中的其他工具一起可见,但不重复悬停图标?


只需设置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每次悬停按下某个按钮或自定义工具的属性。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何添加多个悬停工具而不在工具栏中显示多个图标? 的相关文章

随机推荐