简体   繁体   English

仅在 Python 散景中显示一个字形的 Hover 工具提示

[英]Only show Hover Tooltip for One Glyph in Python bokeh

I want to have my hovertool, showing only when I hover above the diamonds.我想要我的悬停工具,仅当我在钻石上方的 hover 时显示。 As you will see my plot contains diamonds and lines.如您所见,我的 plot 包含菱形和线条。

tooltips = [("Year", "@x{0}"), ("Numbers", "@y{0}")]
p = figure(plot_width=800, plot_height=400,tooltips=tooltips)
p.diamond(df3reset["Years"], df3reset["Numbers"], size=20,
color="navy", alpha=0.5)
p.line(df3reset["Years"], df3reset["Numbers"], line_width=2)
p.xaxis.axis_label = 'Year'
p.yaxis.axis_label = 'Number of dogs'
show(p)

I dont want the hovertool to show the information on the line only while hovering over the diamonds, what would be the solution?我不希望悬停工具仅在将鼠标悬停在钻石上时才显示在线信息,解决方案是什么?

Greetings问候

Remove tooltips from figure then:然后从figure删除tooltips

diamonds = p.diamond(df3reset["Years"], df3reset["Numbers"], size=20, color="navy", alpha=0.5)
p.add_tools(HoverTool(tooltips=tooltips, renderers=[diamonds]))

This can also be accomplished keeping tooltips as you currently have:这也可以通过保持当前的tooltips来完成:

p = figure(..., tooltips=tooltips)

r = p.diamond(...)

# restrict to just one renderer
p.hover.renderers = [r]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM