How to add multiple Hover Tools without showing multiple icons in the toolbar?

走远了吗. 提交于 2019-12-12 17:27:07

问题


Following the example here I have added multiple tooltips to a stacked bar chart. I also want to have other tools available in the toolbar above the plot, but when multiple hover tools are created using the process in the example it creates multiple icons in the tool bar, leaving it looking messy like this:

Is there a way to add multiple hover tools, and have the toolbar visible with other tools in it, but not duplicate the hover icon?


回答1:


Just set the toggleable attribute to False. Check this example, where the hover tool button is hidden:

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)

Well, and if you want to use only one button then you might use only one hover tool. The model CustomJSHover may be useful for you.

As a workaround you can also update the renderers attribute of each hover pressing some button or custom tool.



来源:https://stackoverflow.com/questions/53216167/how-to-add-multiple-hover-tools-without-showing-multiple-icons-in-the-toolbar

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