Reputation: 488
I am using the Python
library networkx
to create a directed graph with almost 2k nodes, and I want to visualize the graph using vis.js
library
I know how to export it as Json, but I am not able to generate a compatible format to use it directly into vis.js
I should have a json String output that looks like:
nodes:
[
{id: 1, label: 'a'},
{id: 2, label: 'b'},
{id: 3, label: 'c'}
]
edges:
[
{from: 1, to: 2, label: 'label1'},
{from: 1, to: 3, label: 'label2'},
{from: 2, to: 4, label: 'label3'},
{from: 2, to: 5, label: 'label3'}
]
Upvotes: 3
Views: 4056
Reputation: 2611
There is port to Jupyter
of visJS
. you can find it here.
The package is in Python 2
but the porting to Python 3
has started.
Please note that as mentioned, it only works with Jupyter
(which is great, if you ask me!).
Upvotes: 0
Reputation: 9798
I am not familiar with viz.js
but if it's not a hard requirement I suggest you export your graph to GEXF:
G = nx.path_graph(4) # your graph here
nx.write_gexf(G, "test.gexf")
And then import it into Sigma.js, a dedicated high performance graph drawing library, using the dedicated GEXF importer plugin.
Upvotes: 2