☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Tooltip position dosen't follow the current mouse cursor position

Community Supporthoverbokeh
b02202040
b02202040

I use hovertool and set point_policy=“follow_mouse”,but It seems dosen’t work.The tooltip postion is still beside the line not the mouse cursor position.

from bokeh.plotting import figure, show
from bokeh.models import HoverTool

x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

p = figure(title="Simple line example", x_axis_label="x", y_axis_label="y")

p.line(x, y, legend_label="Temp.", line_width=2)

tool_1 = HoverTool(
    tooltips=[
        ("x_value", "@x"),
        ("y_value", "@y"),
    ],
    mode='vline',
    point_policy="follow_mouse",
)
p.add_tools(tool_1)
show(p)

here is the figure


below is what I want

Thanks a lot!!

⌁   Link to post
Bryan
Bryan

point_policy only applies to point-like glyphs, e.g. scatter markers. You want to set line_policy="none" (by default line tries to snap to the nearest point). FWIW I would not enable this combination without adding a vertical crosshair as is it otherwise very hard for a user to visually correlate the far-away mouse position with the line at all.

⌁   Link to post
b02202040
b02202040

I think i got your point! Thanks!
May I ask another question about tooltips position?
Is it possible to fix tooltips position (like top left) when the mouse cursor moving around different postion?

⌁   Link to post
Bryan
Bryan

Not presently. The original tooltip class was added very long ago as a private implementation detail and has a lot of baggage as a result. How best to surface a user-accessible and configurable version has been a source of some debate. In any case, it is still an open issue. Your best best for now would be to update the contents of a Div next to the plot, or update the values of text glyphs [1] inside the plot in a hover tool callback.


  1. Or possibly Label or LabelSet annotations. ↩︎

⌁   Link to post

End of archived discussion · Replies are disabled