Hello, I am trying to create a plot with HoverTool inspections for only some of the glyphs and not others. I have a plot with a scatter plot of points, and several rectangles overlaid over the points. I want to have it such at hovering over the rectangles displays tooltips information, but hovering over the points does not. The rectangles are the key feature of the plot but the points are needed for context.
Here I have generated a minimal reproducible example with some dummy data, and screenshot of what it renders. Currently it’s not even showing the thing I want it to show, the name of each rectangle. But it also shows info when the dots are hovered over as well.
I appreciate any guidance on how to display just the rectangle names without also displaying hover info for the dots as well. I’ve done a good amount of googling and trial and error and can’t figure it out.
Cheers.
from bokeh.plotting import figure, show, output_file, save
from bokeh.models import HoverTool
import numpy as np
datadict={
'x':np.random.normal(size=1000), 'y':np.random.normal(size=1000),
}
data=ColumnDataSource(data=datadict)
datadict2={'RectCentersX':[-0.3,0.4], 'RectCentersY':[-0.2,0.2],
'RectWidths':[0.3,0.2], 'RectHeights':[0.2,0.6],
'RectNames':['Jim','Bob']}
data2=ColumnDataSource(data=datadict2)
tools = "hover, zoom_in, zoom_out, save, undo, redo, reset, pan"
tooltips = [
('Name', '@RectNames')
]
hover = HoverTool(mode='mouse', line_policy='nearest',
tooltips=tooltips)
p1 = figure(width=900, height=750,
tools=[tools, hover], toolbar_location="above")
p1.circle('x','y', source=data, color='grey', size=1.5)
p1.rect(source=data2, x='RectCentersX', y='RectCentersY', width='RectWidths', height='RectHeights',
width_units="data", height_units="data", fill_alpha = 0.4)
show(p1)