Tushar
Tushar

Reputation: 21

Python Bokeh - HoverTool: Coordinates for the figure and not data points

I am using the Bokeh version 1.0.3 in Windows and Python 3.6.6.

I have a scatter plot and what I am trying to figure out is to get x, y coordinates of the figure when the mouse cursor is inside the (rectangular) figure but outside/ not pointing the scatter plot points.

The code is here:

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

N = 10
x = [1,2,3,4,5,6,7,8,9,10]
y = [-1,2,-3,4,5,1,-2,3,-4,-5]
r = 0.3
hover = HoverTool(
    tooltips=[
        ("index", "$index"),
        ("data (using $) (x,y)", "($x, $y)"),
        ("data (using @) (x,y)", "(@x, @y)"),
        ("canvas (x,y)", "($sx, $sy)")
    ])
TOOLS = [hover]

p = figure(tools="hover,reset,save")
p = figure(tools=TOOLS)
p.scatter(x, y, radius=r, fill_alpha=0.6,line_color=None)
show(p)

Here for example when we point at the yellow highlighted region, we shall get the x,y coordinates.

img

Upvotes: 2

Views: 1600

Answers (1)

bigreddot
bigreddot

Reputation: 34568

As of Bokeh 1.0.4, the built-in hover tool does not have such a mode. The hover tool only displays when a glyph is "hit" by the cursor. The reason for this is that field specifiers such as @x mean "show the value in the CDS, for the glyph under the cursor". If there is no glyph under the cursor, what should that field in the tooltip show?

As a alternative, you might use low level mouse events to update some fixed Div outside the plot with location information. A relevant example is here.

Upvotes: 3

Related Questions