I am trying to display the node values (index,club) in karateclub network example as shown in the demos. However when I include the following line the node index and clubs displayed by HoverTool becomes ???
graph_renderer.inspection_policy = EdgesAndLinkedNodes()
How can I resolve this? The full code and screenshot is attached
import networkx as nx
from bokeh.io import output_file, show
from bokeh.models import (BoxSelectTool, Circle, EdgesAndLinkedNodes, HoverTool,
MultiLine, NodesAndLinkedEdges, Plot, Range1d, TapTool, ResetTool)
from bokeh.palettes import Spectral4
from bokeh.plotting import from_networkx
G=nx.karate_club_graph()
plot = Plot(plot_width=1200, plot_height=1000,
x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.title.text = "Graph Interaction Demonstration"
SAME_CLUB_COLOR, DIFFERENT_CLUB_COLOR = "black", "red"
edge_attrs = {}
for start_node, end_node, _ in G.edges(data=True):
edge_color = SAME_CLUB_COLOR if G.nodes[start_node]["club"] == G.nodes[end_node]["club"] else DIFFERENT_CLUB_COLOR
edge_attrs[(start_node, end_node)] = edge_color
nx.set_edge_attributes(G, edge_attrs, "edge_color")
# index =[];club = [];
# for index_val, node_name in G.nodes(data=True):
# index.append(index_val)
# club.append(node_name['club'])
graph_renderer = from_networkx(G, nx.spring_layout, scale=1.1, center=(0,0))
plot.add_tools(HoverTool(tooltips=[("index", "@index"), ("club", "@club")]),
TapTool(),
BoxSelectTool(),
ResetTool())
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=15, fill_color=Spectral4[1])
graph_renderer.edge_renderer.glyph = MultiLine(line_color="edge_color", line_alpha=0.5, 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)
# graph_renderer.node_renderer.data_source.data['index'] = index
# graph_renderer.node_renderer.data_source.data['club'] = club
graph_renderer.selection_policy = NodesAndLinkedEdges()
graph_renderer.inspection_policy = EdgesAndLinkedNodes()
plot.renderers.append(graph_renderer)
output_file("interactive_graphs.html")
show(plot)
Also I would like to know how to make the box that shows up when clicking on a node persist when I have selected that node. Thanks!