I am plotting very many points in Bokeh, and I have added the HoverTool to the list of tools of the figure, so that the mouse shows the x,y
coordinates of the mouse when close to a glyph.
When the mouse gets close to a set of glyphs closely packed together, I get as many tooltips as glyphs. I want instead only one tooltip, the one of the closest glyph. This isn't just a presentation detail, because for very many points this results:
- in slow interaction with the plot, with the browser getting stuck while all tooltips are generated
- in a very long tooltip, where the same information is repeated as many times as many glyphs are close to the cursor
An example follows, with the code to replicate the behaviour:
import numpy.random
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import HoverTool
output_notebook()
hover = HoverTool()
hover.tooltips = [("(x,y)", "($x, $y)")]
x = numpy.random.randn(500)
y = numpy.random.randn(500)
p = figure(tools=[hover])
p.circle(x,y, color='red', size=14, alpha=0.4)
show(p)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…