我有一个网络,有这样的节点:
[('user_0', {'pk': 2, 'tname': 'user_0'}), ('user_1', {'pk': 3, 'tname': 'user_1'}), ('user_2', {'pk': 4, 'tname': 'user_2'}), ('user_3', {'pk': 5, 't': 'user_3'}), ('user_4', {'pk': 6, 't': 'user_4'})]
还有我的绘图代码is essentially a combination of the two examples in the documentation。如下:
# Create plot
plot = Plot(plot_width=600,
plot_height=600,
x_range=Range1d(-1.1,1.1),
y_range=Range1d(-1.1,1.1))
# Set title
plot.title.text = "Graph Interaction Demonstration"
# Create and set up graph renderer ------------------------------------
# Use renderer to plot from network x, with given layout
graph = self.as_plottable()
nodes = list(graph .nodes)
n_nodes = len(list(graph .nodes))
graph_renderer = from_networkx(graph ,
nx.shell_layout,
nlist=[nodes[0:int(n_nodes/3)],
nodes[int(n_nodes/3):2*int(n_nodes/3)],
nodes[2*int(n_nodes/3):]],
scale=1,
center=(0,0))
# Add interaction tools
node_hover_tool = HoverTool(tooltips=[
('Name','@tname'),
('ID','@pk')
])
plot.add_tools(node_hover_tool,
BoxZoomTool(),
ResetTool())
graph_renderer.node_renderer.glyph = Circle(size=8, fill_color=Spectral4[0])
graph_renderer.node_renderer.selection_glyph = Circle(size=8, fill_color=Spectral4[2])
graph_renderer.node_renderer.hover_glyph = Circle(size=12, fill_color=Spectral4[1])
graph_renderer.edge_renderer.glyph = MultiLine(line_color="#BFBFBF", line_alpha=0.8, line_width=3)
graph_renderer.edge_renderer.selection_glyph = MultiLine(line_color=Spectral4[2], line_width=3)
graph_renderer.edge_renderer.hover_glyph = MultiLine(line_color=Spectral4[1], line_width=3)
# Provide logic for selection of graph components
graph_renderer.selection_policy = NodesAndLinkedEdges()
# Provide logic for inspection of graph components
graph_renderer.inspection_policy = EdgesAndLinkedNodes()
# Add network graph renderer to plot
plot.renderers.append(graph_renderer)
# Output graph to a file
output_file(filename)
# Plot graph
show(plot)
我已经尝试过按顺序排列,更改节点属性的名称以及进行其他各种调整,但是我的hovertip数据始终显示为“名称:???”,“ ID:???”。我已经读到,当您的数据源中实际上没有正确的列时,可能会发生这种情况,但是我打印了dict:
graph_renderer.node_renderer.data_source.data
它同时具有“ tname”和“ pk”的条目。我很沮丧有什么想法吗?
答案 0 :(得分:1)
解决了问题,问题在于将我的检查政策设置为EdgesAndLinkedNodes()
。这导致我的工具提示在边缘而不是节点中寻找信息。