pyvis库如何使用函数nt.from_nx从Networkx转换我已经准备好的网络图



我正在尝试使用pyvis库,使用函数nt.from_nx image 从(Networkx(转换我已经准备好的网络图

我的代码:

strong_G (graph object)
from pyvis.network import Network
import networkx as nx
nx_graph = strong_G
nt = Network("500px", "500px")
# populates the nodes and edges data structures
nt.from_nx(nx_graph)
nt.show("nx.html")

这是库中显示的例子

(https://pyvis.readthedocs.io/en/latest/tutorial.html#example-可视化-一次性游戏-角色网络(

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

有什么解决办法吗?

我使用更简单的代码:

net = Network(height="1000px", width="100%", bgcolor="#222222", bgcolor="#222222", font_color="white",directed=True)
net.from_nx(strong_G,show_edge_weights=True)
net.show_buttons(filter_=['physics'])
net.show("test.html")

最新更新