Bokeh Plotting: Enable tooltips for only some glyphs(散景绘图:仅对某些字形启用工具提示)
问题描述
我有一个带有一些字形的图形,但只想显示某些字形的工具提示.目前有没有办法在 Bokeh 中实现这一点?
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.
推荐答案
感谢 Google Groups 中的这个页面,我想出了如何做到这一点.链接在这里
Thanks to this page in Google Groups I figured out how this can be done. Link here
编辑 2015-10-20:不幸的是,谷歌群组链接似乎不再有效.这是来自 Sarah Bird @bokehplot 的消息.
Edit 2015-10-20: looks like the google group link doesn't work anymore unfortunately. It was a message from Sarah Bird @bokehplot.
编辑 2017-01-18:目前这会在工具栏中添加多个悬停工具图标.这可能会导致问题.github here 已经存在一个问题.或者,在下面的答案中尝试@terry 的解决方案.
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.
基本上你需要(散景版本 0.9.2):
Essentially you need to (bokeh version 0.9.2):
- 创建图形时不要在
tools中添加hover - 单独创建字形
- 为您的图形添加字形
- 为这组字形设置悬停工具
- 为您的人物添加悬停工具
例子:
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源码 例如:
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)
这篇关于散景绘图:仅对某些字形启用工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:散景绘图:仅对某些字形启用工具提示
基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
