我在Bokeh中遇到这个问题,即悬停突出显示的边缘会随着鼠标移动而变化。它显示了其中一些,当鼠标位于节点的北边时,其中一些当鼠标位于节点的南边时。当鼠标悬停在该节点上时,我要突出显示节点边缘的[[all。
这里是示例: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()
这样,您的主要重点是节点,而不是边缘。您当前的解决方案将所有边都悬停,尽管它们靠近节点,但它们可能不够靠近而无法选择。