diff env/share/doc/networkx-2.5/examples/pygraphviz/plot_pygraphviz_attributes.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/share/doc/networkx-2.5/examples/pygraphviz/plot_pygraphviz_attributes.py	Mon Mar 22 18:12:50 2021 +0000
@@ -0,0 +1,38 @@
+"""
+=====================
+Pygraphviz Attributes
+=====================
+
+An example showing how to use the interface to the pygraphviz
+AGraph class to convert to and from graphviz.
+
+Also see the pygraphviz documentation and examples at
+http://pygraphviz.github.io/
+"""
+
+import networkx as nx
+
+# networkx graph
+G = nx.Graph()
+# ad edges with red color
+G.add_edge(1, 2, color="red")
+G.add_edge(2, 3, color="red")
+# add nodes 3 and 4
+G.add_node(3)
+G.add_node(4)
+
+# convert to a graphviz agraph
+A = nx.nx_agraph.to_agraph(G)
+
+# write to dot file
+A.write("k5_attributes.dot")
+
+# convert back to networkx Graph with attributes on edges and
+# default attributes as dictionary data
+X = nx.nx_agraph.from_agraph(A)
+print("edges")
+print(list(X.edges(data=True)))
+print("default graph attributes")
+print(X.graph)
+print("node node attributes")
+print(X.nodes.data(True))