简体   繁体   English

hvplot networkx节点名称悬停

[英]hvplot networkx node names with hover

I am using hvplot (version 0.4.0) with a networkx undirected graph (networkx version 2.1). 我正在使用hvplot(版本0.4.0)和networkx无向图(networkx版本2.1)。 When plotting the graph using the bokeh backend, I would like the hover to display the node name and not "index:number". 使用散景后端绘制图形时,我希望悬停显示节点名称而不是“index:number”。

All the examples online in the docs have "index:number", I have tried to pass the names to the "labels" kwargs but that results in an error: 文档中的所有在线示例都有“index:number”,我试图将名称传递给“标签”kwargs,但这会导致错误:

DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: DataError:提供的数据不包含指定的尺寸,未找到以下尺寸:

import networkx as nx
import hvplot.networkx as hvnx
import holoviews as hv
hv.extension('bokeh')
GG = nx.Graph()
GG.add_edge('A','B')
GG.add_edge('B','C')
GG.add_edge('C','A')
hvnx.draw(GG)

在此输入图像描述

Looping through the GG object, provides the following info 循环通过GG对象,提供以下信息

for ii in GG.nodes():

    print(ii,type(ii))

A <class 'str'>
C <class 'str'>
B <class 'str'>

for ee in GG.edges():

    print(ee,type(ee))

('A', 'C') <class 'tuple'>
('A', 'B') <class 'tuple'>
('C', 'B') <class 'tuple'>

It seems like what you are trying to do should be the default behavior and likely represents some regression in HoloViews. 看起来你想要做的应该是默认行为,并且可能代表HoloViews中的一些回归。 That said the actual hover index data is actually being added to the plot it's just not referenced correctly. 也就是说,实际的悬停指数数据实际上被添加到它没有正确引用的图中。 In your example you can make sure it is used correctly by explicitly declaring a bokeh HoverTool : 在您的示例中,您可以通过显式声明散景HoverTool来确保正确使用它:

from bokeh.models import HoverTool

GG = nx.Graph()
GG.add_edge('A','B')
GG.add_edge('B','C')
GG.add_edge('C','A')
hvnx.draw(GG).opts(tools=[HoverTool(tooltips=[('index', '@index_hover')])])

在此输入图像描述

I have already filed an issue to make a note of this regression and you should expect this to be fixed in holoviews 1.12.0. 我已经提交了一个问题来记录这个回归,你应该期望在holoviews 1.12.0中修复它。

My solution 我的解决方案

var selected_nodes = cb_data.source.selected["1d"].indices.map(function (selected_node_index) {
  return cb_data.source.data.index_hover[selected_node_index];
});


see cb_data.source.selected["1d"].indices 见cb_data.source.selected [“1d”]。indices

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM