Only show Hover Tooltip for One Glyph in Python bo

2020-05-06 08:05发布

I want to have my hovertool, showing only when I hover above the diamonds. As you will see my plot contains diamonds and lines.

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

2条回答
▲ chillily
2楼-- · 2020-05-06 08:31

This can also be accomplished keeping tooltips as you currently have:

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

r = p.diamond(...)

# restrict to just one renderer
p.hover.renderers = [r]
查看更多
Melony?
3楼-- · 2020-05-06 08:40

Remove tooltips from figure then:

diamonds = p.diamond(df3reset["Years"], df3reset["Numbers"], size=20, color="navy", alpha=0.5)
p.add_tools(HoverTool(tooltips=tooltips, renderers=[diamonds]))
查看更多
登录 后发表回答