summaryrefslogtreecommitdiff
path: root/examples/external/plot_jit.py
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2020-12-06 00:57:17 -0800
committerGitHub <noreply@github.com>2020-12-06 00:57:17 -0800
commita678c7ad3a3d35a68e7612fceba86b23a880353e (patch)
tree4eb24921b14cfdeef3b4a14f3fe7756f864b89ae /examples/external/plot_jit.py
parent24476c8697d3f3ba877d2f99952e7d2b1786bfab (diff)
downloadnetworkx-a678c7ad3a3d35a68e7612fceba86b23a880353e.tar.gz
Refactor gallery (#4422)
* Add external directory * Move Javascript and JIT * Remove application section * Consolidate and move pygraphviz examples * Clean up imports * Reorder * Fix subclass examples
Diffstat (limited to 'examples/external/plot_jit.py')
-rw-r--r--examples/external/plot_jit.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/external/plot_jit.py b/examples/external/plot_jit.py
new file mode 100644
index 00000000..e78c46dd
--- /dev/null
+++ b/examples/external/plot_jit.py
@@ -0,0 +1,37 @@
+"""
+================================
+JavaScript InfoVis Toolkit (JIT)
+================================
+
+An example showing how to use the JavaScript InfoVis Toolkit (JIT)
+JSON export
+
+See the JIT documentation and examples at https://philogb.github.io/jit/
+"""
+
+import json
+
+import matplotlib.pyplot as plt
+import networkx as nx
+
+# add some nodes to a graph
+G = nx.Graph()
+
+G.add_node("one", type="normal")
+G.add_node("two", type="special")
+G.add_node("solo")
+
+# add edges
+G.add_edge("one", "two")
+G.add_edge("two", 3, type="extra special")
+
+# convert to JIT JSON
+jit_json = nx.jit_data(G, indent=4)
+print(jit_json)
+
+X = nx.jit_graph(json.loads(jit_json))
+print(f"Nodes: {list(X.nodes(data=True))}")
+print(f"Edges: {list(X.edges(data=True))}")
+
+nx.draw(G, pos=nx.planar_layout(G), with_labels=True)
+plt.show()