多亏了Google网上论坛中的此页面,我才知道如何做到这一点。
连结这里
编辑2015-10-20 :很遗憾,似乎Google网上论坛链接不再起作用。这是来自Sarah Bird @bokehplot的消息。
编辑2017年1月18日
:当前,这会将多个悬停工具图标添加到工具栏。这可能会引起问题。目前已经在GitHub上提交一个问题在这里。或者,在下面的答案中尝试@tterry的解决方案。
基本上,您需要(散景版本0.9.2):
- 创建图形时不要添加
hover
到您tools
的图形中 - 分别创建字形
- 在您的图形上添加字形
- 为这组字形设置悬停工具
- 将悬停工具添加到您的图形中
例:
import bokeh.models as bkmimport bokeh.plotting as bkpsource = bkm.ColumnDataSource(data=your_frame)p = bkp.figure(tools='add the tools you want here, but no hover!')g1 = bkm.Cross(x='col1', y='col2')g1_r = p.add_glyph(source_or_glyph=source, glyph=g1)g1_hover = bkm.HoverTool(renderers=[g1_r], tooltips=[('x', '@col1'), ('y', '@col2')])p.add_tools(g1_hover)# now repeat the above for the next sets of glyphs you want to add. # for those you don't want tooltips to show when hovering over, just don't # add hover tool for them!另外,如果需要将图例添加到要添加的每个字形中,请尝试使用
bokeh.plotting_helpers._update_legend()method。github来源例如:
_update_legend(plot=p, legend_name='data1', glyph_renderer=g1_r)



