散景悬停突出显示的边缘随鼠标移动而变化

Bokeh hover highlighted edges change by mouse movement

我的 Bokeh 有这个问题,悬停突出显示的边缘会因鼠标移动而改变。当鼠标在节点的北边时,它会显示其中的一些,而当鼠标在节点的南边时,它会显示一些。当鼠标悬停在该节点上时,我希望突出显示该节点的 所有 边缘。

示例如下:

import networkx as nx

from bokeh.models import Range1d, MultiLine, Circle, HoverTool
from bokeh.models.graphs import from_networkx, EdgesAndLinkedNodes
from bokeh.plotting import figure, show

G=nx.karate_club_graph()

plot = figure(plot_width=400, plot_height=400,
            x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.add_tools(HoverTool(tooltips=None))

r = from_networkx(G, nx.circular_layout, scale=1, center=(0,0))

r.node_renderer.glyph = Circle(size=15, fill_color='#2b83ba')
r.node_renderer.hover_glyph = Circle(size=15, fill_color='#abdda4')

r.edge_renderer.glyph = MultiLine(line_alpha=0, line_width=5)  # zero line alpha
r.edge_renderer.hover_glyph = MultiLine(line_color='#abdda4', line_width=5)

r.inspection_policy = EdgesAndLinkedNodes()
plot.renderers.append(r)

show(plot)

以及两张问题截图:

两张截图都看不到鼠标,不知道为什么,鼠标都在左边的节点上。稍微移动一下,突出显示的边缘就会发生变化。

你应该检查

from bokeh.models.graphs import NodesAndLinkedEdges 而不是 EdgesAndLinkedNodes

所以, r.inspection_policy = NodesAndLinkedEdges()

这样你的主要关注点是节点,而不是边缘。您当前的解决方案悬停在所有边缘上,尽管它们靠近节点,但它们可能不够接近以选中所有边缘。