python - 无法填充 Bokeh 网络图中的悬停工具提示值

标签 python networking plot graph bokeh

我有一个网络,其节点如下:

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

我尝试过调整事物的顺序、更改节点属性的名称以及各种其他调整,但我的悬停提示数据始终显示为“名称:???”、“ID:???”。我读到,当您的数据源中实际上没有正确的列时,可能会发生这种情况,但我打印了字典:

graph_renderer.node_renderer.data_source.data

它有“tname”和“pk”的条目。我很困惑。有什么想法吗?

最佳答案

解决了,问题是将我的检查策略设置为EdgesAndLinkedNodes()。这导致我的工具提示在边缘而不是节点中查找信息。

关于python - 无法填充 Bokeh 网络图中的悬停工具提示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53680572/

相关文章:

python - 如何验证 urllib2 脚本以便从 Django 站点访问 HTTPS Web 服务?

android - 如何监控 Android 上的传入和传出 IP 流量

docker - Kubernetes/minikube 无法 ping 通同一集群中的 pod,但 nslookup 可以工作

从 gnuplot 中的一个非常大的文件中绘制子图

r - 在图形上手动绘制

python - 调试简单的 Python 价格代码

python - 使用xhtml2pdf,用实际链接替换超链接

python - 将焦点放在 Tkinter 窗口上(取决于平台?)

c - 使用C打印服务器IP地址

python - 修改Matplotlib五彩直方图脚本使其累积