散景绘图:仅为某些字形启用工具提示 [英] Bokeh Plotting: Enable tooltips for only some glyphs

查看:133
本文介绍了散景绘图:仅为某些字形启用工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些带有一些字形的图形,但只希望显示某些字形的工具提示。目前有一种方法可以在Bokeh中实现这一点吗?



或者,有没有办法将两个数字打在一起?看起来这样可以让我完成我想要做的事情。

感谢Google Groups中的这个页面,我想出了如何这可以做到。
链接此处



编辑2015-10-20 :看起来像谷歌组链接不不幸的是工作。这是来自Sarah Bird @bokehplot的消息。

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



基本上你需要(散景版本0.9.2):


  1. 不会在工具中添加 hover >
  2. 单独创建字形

  3. 为图形添加字形
  4. 为这组字形设置悬停工具
  5. li>
  6. 将悬停工具添加到您的数据中

示例:

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

source = bkm.ColumnDataSource(data = your_frame)
p = bkp.figure(tools ='添加你想要的工具,但没有悬停!')
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)

#现在重复上面的nex t套你想添加的字形。
#对于那些你不希望工具提示在悬停时显示的,只是不要
#为他们添加悬停工具!

另外,如果您需要为每个要添加的字形添加图例,请尝试使用 bokeh.plotting_helpers._update_legend()方法。 github源例如:

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


I have a figure with some glyphs, but only want tooltips to display for certain glyphs. Is there currently a way to accomplish this in Bokeh?

Alternatively, is there a way to plot two figures on top of each other? It seems like that would let me accomplish what I want to do.

解决方案

Thanks to this page in Google Groups I figured out how this can be done. Link here

Edit 2015-10-20: looks like the google group link doesn't work anymore unfortunately. It was a message from Sarah Bird @bokehplot.

Edit 2017-01-18: Currently this would add multiple hover tool icons to the tool bar. This may cause problems. There is already an issue filed at github here. Alternatively, try @tterry's solution in the answer below.

Essentially you need to (bokeh version 0.9.2):

  1. not add hover in your tools when you create the figure
  2. create glyphs individually
  3. add glyphs to your figure
  4. set up the hover tool for this set of glyphs
  5. add the hover tool to your figure

Example:

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!

Also if you need to add legend to each of the glyphs you are adding, try using bokeh.plotting_helpers._update_legend() method. github source Eg:

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

这篇关于散景绘图:仅为某些字形启用工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆