python - Bokeh 绘图 : Enable tooltips for only some glyphs

标签 python plot hover tooltip bokeh

我有一个带有一些字形的图形,但只想显示某些字形的工具提示。目前有没有办法在 Bokeh 中实现这一点?

或者,有没有办法将两个图形相互叠加?看来这会让我完成我想做的事情。

最佳答案

感谢 Google Groups 中的这个页面,我想出了如何做到这一点。 Link here

编辑 2015-10-20:不幸的是,谷歌群组链接似乎不再有效。这是来自 Sarah Bird @bokehplot 的消息。

编辑 2017-01-18:目前这会在工具栏中添加多个悬停工具图标。这可能会导致问题。在 github here 上已经提交了一个问题.或者,在下面的答案中尝试@terry 的解决方案。

基本上你需要( Bokeh 版本 0.9.2):

  1. 创建图形时不要在 tools 中添加 hover
  2. 单独创建字形
  3. 为您的图形添加字形
  4. 为这组字形设置悬停工具
  5. 为您的人物添加悬停工具

例子:

import bokeh.models as bkm
import bokeh.plotting as bkp

source = 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() 方法。 github source例如:

_update_legend(plot=p, legend_name='data1', glyph_renderer=g1_r)

关于python - Bokeh 绘图 : Enable tooltips for only some glyphs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29435200/

相关文章:

python - Linux CentOS 7,如何设置Python2.7为默认Python版本?

python - Matplotlib : quiver and imshow superimposed, 如何设置两个颜色条?

使用 RGB 颜色进行 MATLAB 绘图

r - 你如何让 x-lab 标签变成斜体而不是 y-lab 标签? (在R)

python - 如何从具有透明背景的 matplotlib 导出绘图?

css - :hover behavior across mobile devices

python - 将列表中的相同值组合起来以显示为范围

python - 从字符串列表中删除括号和逗号(python 和 sqlite)

css - 尝试用 CSS 制作一个 diaporama 元素符号列表导航器

jQuery .fadeTo 添加元素