Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

python - How to trigger visual effects of hover without showing a hover tooltip

I have a large heatmap in which I plot the cells via p.image with a hover that shows the exact values. Additionally, when hovering over a region the region should be highlighted with an outline. A p.rect with only hover_outline_alpha=1 works exactly as I want it, but additionally it shows a hover tooltip. Is there any way to disable the hover tooltip while still having the visual changes triggered?

from bokeh.palettes import Viridis256
from bokeh.models import HoverTool
from bokeh.plotting import figure

image = [np.array([[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])]
p = figure(x_range=["aa", "ab", "ba", "bb"], y_range=["aa", "ab", "ba", "bb"], 
           tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")])

# heatmap 
image_renderer = p.image(image=image, x=0, y=0, dw=4, dh=4, palette=Viridis256)

# outlines for each region
rect_renderer = p.rect(x=[1, 1, 3, 3], y=[1, 3, 1, 3], width=2, height=2, 
       fill_alpha=0.0, line_alpha=0.0, hover_line_alpha=1, line_width=3)


# Disables the tooltip on rect_renderer, but also does not trigger the outline
p.hover.renderers = [image_renderer]
# Seperate hover triggers the hover, but also shows an empty tooltip.
p.add_tools(HoverTool(renderers=[rect_renderer], tooltips=""))

show(p)
question from:https://stackoverflow.com/questions/66061585/how-to-trigger-visual-effects-of-hover-without-showing-a-hover-tooltip

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I cross posted this question to the bokeh discourseforum and bryan answered:

Set toolips=None, not the empty string. This is documented at the bottom of the reference guide entry for tooltips:

None is also a valid value for tooltips. This turns off the rendering of tooltips.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...