Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / examples / jit / plot_rgraph.py @ 5cef0f13

History | View | Annotate | Download (835 Bytes)

1
#!/usr/bin/env python
2
"""
3
======
4
Rgraph
5
======
6

7
An example showing how to use the JavaScript InfoVis Toolkit (JIT)
8
JSON export
9

10
See the JIT documentation and examples at http://thejit.org
11

12
"""
13
__author__ = """Ollie Glass (ollieglaskovik@gmail.com)"""
14

    
15
import json
16

    
17
import matplotlib.pyplot as plt
18
import networkx as nx
19
from networkx.readwrite.json_graph import jit_data, jit_graph
20

    
21
# add some nodes to a graph
22
G = nx.Graph()
23

    
24
G.add_node("one", type="normal")
25
G.add_node("two", type="special")
26
G.add_node("solo")
27

    
28
# add edges
29
G.add_edge("one", "two")
30
G.add_edge("two", 3, type="extra special")
31

    
32
# convert to JIT JSON
33
jit_json = jit_data(G, indent=4)
34
print(jit_json)
35

    
36
X = jit_graph(json.loads(jit_json))
37
print("Nodes: %s" % list(X.nodes(data=True)))
38
print("Edges: %s" % list(X.edges(data=True)))
39

    
40
nx.draw(G, with_labels=True)
41
plt.show()