Last active
May 29, 2019 20:47
-
-
Save clayadavis/8983421 to your computer and use it in GitHub Desktop.
Convert networkx graph to d3 graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nodes = [{'name': n, 'group': G.node[n]['question_id'], 'size': G.node[n]['count']} for n in G] | |
l = G.edges() | |
edges = [{'source': l.index(s), 'target': l.index(t), 'value': G[s][t]['weight']} for s,t in itertools.product(l, l) if s in G and t in G[s]] | |
json.dump({'nodes': nodes, 'links': edges}, open('filename.json', 'w')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment