如何在不显示悬停工具提示的情况下触发悬停的视觉效果

2024-10-01 11:26:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个大的热图,其中我通过p.image绘制单元,并用鼠标悬停显示精确的值。 此外,当鼠标悬停在某个区域上时,该区域应以轮廓突出显示。只有hover_outline_alpha=1p.rect完全符合我的要求,但它还显示悬停工具提示。是否有任何方法可以在仍然触发视觉更改的情况下禁用悬停工具提示

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)

Tags: 工具thefromrectimageimportalpha区域
1条回答
网友
1楼 · 发布于 2024-10-01 11:26:57

我向博克语篇论坛提出这个问题,布莱恩回答:

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.

相关问题 更多 >