Reputation: 21
I am trying to display a graph I have created using networkx, but the nodes are overlapping. I want to display it in HTML so I can move nodes using the mouse (it also adds some interaction to the result).
How can I display my nx graph in HTML?
Up to now, my code is:
G= nx.Graph()
G.add_nodes_from(nodes) # nodes is a list of nodes names (strings)
G.add_edges_from(edges) # edges is a list of edges between nodes above
pos = nx.spring_layout(G, scale=layout_scale, k=k)
plt.figure(figsize=figsize)
nx.draw_networkx(G, pos=pos)
plt.show()
For now, this code results in displaying the plot as some kind of an image (in the SciView of PyCharm).
I would appreciate any help with that!
Thanks!
Upvotes: 2
Views: 5724
Reputation: 21
Hi I use pyvis for interactive display. If I understand correctly, try my code, it should help you
from pyvis.network import Network
import networkx as nx
G=nx.Graph()
G.add_edge('1', '2')
G.add_edge('1', '3')
nx.draw(G, with_labels = True)
nt = Network('500px', '500px')
nt.from_nx(G)
nt.show('nx.html')
Upvotes: 2