2

I have a network, with nodes as such:

[('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'})]

And my plotting code is essentially a combination of the two examples in the documentation. It's as follows:

        # 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)

I've tried shuffling around the order of things, changing the names of my node attributes, and various other adjustments, but my hovertip data always displays as "Name: ???", "ID: ???". I've read that this can happen when you don't actually have the right columns in your data source, but I printed the dict:

graph_renderer.node_renderer.data_source.data

And it had entries for both "tname" and "pk". I'm stumped. Any ideas?

1 Answer 1

3

Solved it, the problem was setting my inspection policy to EdgesAndLinkedNodes(). This was causing my tooltips to look for information in the edges, rather than the nodes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.