Mercurial > repos > shellac > sam_consensus_v3
comparison env/share/doc/networkx-2.5/examples/jit/plot_rgraph.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """ | |
2 ====== | |
3 Rgraph | |
4 ====== | |
5 | |
6 An example showing how to use the JavaScript InfoVis Toolkit (JIT) | |
7 JSON export | |
8 | |
9 See the JIT documentation and examples at http://thejit.org | |
10 | |
11 """ | |
12 | |
13 import json | |
14 | |
15 import matplotlib.pyplot as plt | |
16 import networkx as nx | |
17 from networkx.readwrite.json_graph import jit_data, jit_graph | |
18 | |
19 # add some nodes to a graph | |
20 G = nx.Graph() | |
21 | |
22 G.add_node("one", type="normal") | |
23 G.add_node("two", type="special") | |
24 G.add_node("solo") | |
25 | |
26 # add edges | |
27 G.add_edge("one", "two") | |
28 G.add_edge("two", 3, type="extra special") | |
29 | |
30 # convert to JIT JSON | |
31 jit_json = jit_data(G, indent=4) | |
32 print(jit_json) | |
33 | |
34 X = jit_graph(json.loads(jit_json)) | |
35 print(f"Nodes: {list(X.nodes(data=True))}") | |
36 print(f"Edges: {list(X.edges(data=True))}") | |
37 | |
38 nx.draw(G, with_labels=True) | |
39 plt.show() |