test_nxjs.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # http://networkx.github.io/documentation/latest/examples/javascript/force.html
4 
5 import json
6 import networkx as nx
7 from networkx.readwrite import json_graph
8 
9 G = nx.barbell_graph(6,3)
10 # this d3 example uses the name attribute for the mouse-hover value,
11 # so add a name to each node
12 for n in G:
13  G.node[n]['name'] = n
14 # write json formatted data
15 d = json_graph.node_link_data(G) # node-link format to serialize
16 #d = json_graph.adjacency_data(G)
17 # write json
18 print json.dumps(d, indent=2)