【发布时间】:2021-07-20 05:31:55
【问题描述】:
我已经阅读了文档,并且确实添加了带有属性 weight 的边,但是边的权重没有显示在图上,并且当我将光标悬停在两个节点之间的链接上时,它也没有显示。可以显示重量吗?
代码 sn-p(来源:https://pyvis.readthedocs.io/en/latest/tutorial.html#networkx-integration):
from pyvis.network import Network
import networkx as nx
nx_graph = nx.cycle_graph(10)
nx_graph.nodes[1]['title'] = 'Number 1'
nx_graph.nodes[1]['group'] = 1
nx_graph.nodes[3]['title'] = 'I belong to a different group!'
nx_graph.nodes[3]['group'] = 10
nx_graph.add_node(20, size=20, title='couple', group=2)
nx_graph.add_node(21, size=15, title='couple', group=2)
nx_graph.add_edge(20, 21, weight=5)
nx_graph.add_node(25, size=25, label='lonely', title='lonely node', group=3)
nt = Network('500px', '500px')
# populates the nodes and edges data structures
nt.from_nx(nx_graph)
nt.show('nx.html')
如何显示边的权重?在此示例中,节点 20 和 21 的边的权重。
【问题讨论】:
-
你能发布一个显示问题的最小代码sn-p吗?
-
好的,我会更新的
标签: python networking graph graph-visualization pyvis