I'm trying to get separate hover tooltips for nodes and edges in Bokeh, but haven't been able to get it to work. Could someone point out what I'm doing wrong? I believe the code should look something like this:
from bokeh.io import show, output_notebook
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool
from bokeh.models.graphs import from_networkx, NodesAndLinkedEdges, EdgesAndLinkedNodes
import networkx as nx
output_notebook()
# Generate data
G = nx.karate_club_graph()
nx.set_edge_attributes(G, nx.edge_betweenness_centrality(G), "betweenness_centrality")
# Setup plot
plot = Plot(plot_width=400, plot_height=400,
x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
graph_renderer = from_networkx(G, nx.spring_layout, scale=1, center=(0, 0))
graph_renderer.node_renderer.glyph = Circle(size=15)
graph_renderer.edge_renderer.glyph = MultiLine(line_alpha=0.8, line_width=1)
plot.renderers.append(graph_renderer)
# Add hover
node_hover_tool = HoverTool(renderers=[graph_renderer.node_renderer],
tooltips=[("index", "@index"), ("club", "@club")])
edge_hover_tool = HoverTool(renderers=[graph_renderer.edge_renderer],
tooltips=[("betweenness_centrality", "@betweenness_centrality")],
line_policy="interp")
plot.add_tools(node_hover_tool, edge_hover_tool)
# Show
show(plot)
But I don't see any hover over with this. I've tried a few things to work around this:
- If I remove the
renderers
argument, I can get some hover over, but not specific to the glyphs I want. - If I remove the
renderers
argument from bothHoverTool
s, I'm able to get correct tooltips on the nodes along with abetweenness_centrality: ??
- If I remove the
renderers
argument from bothHoverTool
s and addgraph_renderer.inspection_policy = NodesAndLinkedEdges()
, I get correct tooltips on the nodes - If I remove the
renderers
argument from bothHoverTool
s and addgraph_renderer.inspection_policy = EdgesAndLinkedNodes()
, I get correct tooltips on the edges
I believe this question was asked before on the google group here, but didn't get an answer.
Thanks for any help!