无法在bokeh网络图中填充“悬停工具提示"值

编程入门 行业动态 更新时间:2024-10-25 22:26:19
本文介绍了无法在bokeh网络图中填充“悬停工具提示"值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个网络,有这样的节点:

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

我的绘图代码本质上是以下两个示例的组合文档.如下:

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

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

它同时具有"tname"和"pk"的条目.我很困惑有什么想法吗?

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

推荐答案

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

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.

更多推荐

无法在bokeh网络图中填充“悬停工具提示"值

本文发布于:2023-07-18 20:12:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1148598.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   提示   工具   网络   bokeh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!