使用散景在networkx中边缘两端的工具提示

时间:2017-10-26 20:38:05

标签: networkx bokeh

我正在尝试构建一个可视化,我使用networkx在bokeh中构建图形。我想在边缘的连接节点上添加工具提示。

目前,工具提示显示在单个节点上,显示两个节点的标签。如何分隔工具提示,以便每个节点都有一个标签?谢谢。

P.S这样的事情: enter image description here

plot = Plot(plot_width=700, plot_height=700,
x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.title.text = "Graph Interaction Demonstration"
plot.add_tools(HoverTool(tooltips=[("Bigram","@start+@end")]))

nodes = list(G.nodes())
edges = list(G.edges())
edges_start = [edge[0] for edge in edges]
edges_end = [edge[1] for edge in edges]
node_source = ColumnDataSource(data={'index':nodes})
edge_source = ColumnDataSource(data=dict(
            start=edges_start,
            end=edges_end,

        ))

graph_renderer = GraphRenderer()
graph_renderer.node_renderer.data_source.data = node_source.data
graph_renderer.edge_renderer.data_source.data = edge_source.data
graph_layout=nx.circular_layout(G,scale=1,center=(0,0))
graph_renderer.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
graph_renderer.node_renderer.glyph = Circle(size=15, fill_color=Spectral4[0])
graph_renderer.node_renderer.selection_glyph = Circle(size=15, fill_color=Spectral4[2])
graph_renderer.node_renderer.hover_glyph = Circle(size=25, fill_color=Spectral4[1])

graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_alpha=0.8, line_width=5)
graph_renderer.edge_renderer.selection_glyph = MultiLine(line_color=Spectral4[2], line_width=5)
graph_renderer.edge_renderer.hover_glyph = MultiLine(line_color=Spectral4[1], line_width=5)

#graph_renderer.selection_policy = NodesAndLinkedEdges()
#graph_renderer.inspection_policy = EdgesAndLinkedNodes()

plot.renderers.append(graph_renderer)

0 个答案:

没有答案