Reputation: 1
I'm trying to use the pyvis Library to convert a network graph that I all ready have from( Networkx ) using the function nt.from_nx image
my code :
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")
this is the example shown in the library
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")
any ideas on how to solve it?
Upvotes: 0
Views: 2416
Reputation: 41
I use simpler code:
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")
Upvotes: 0