comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """
2 =====================
3 Pygraphviz Attributes
4 =====================
5
6 An example showing how to use the interface to the pygraphviz
7 AGraph class to convert to and from graphviz.
8
9 Also see the pygraphviz documentation and examples at
10 http://pygraphviz.github.io/
11 """
12
13 import networkx as nx
14
15 # networkx graph
16 G = nx.Graph()
17 # ad edges with red color
18 G.add_edge(1, 2, color="red")
19 G.add_edge(2, 3, color="red")
20 # add nodes 3 and 4
21 G.add_node(3)
22 G.add_node(4)
23
24 # convert to a graphviz agraph
25 A = nx.nx_agraph.to_agraph(G)
26
27 # write to dot file
28 A.write("k5_attributes.dot")
29
30 # convert back to networkx Graph with attributes on edges and
31 # default attributes as dictionary data
32 X = nx.nx_agraph.from_agraph(A)
33 print("edges")
34 print(list(X.edges(data=True)))
35 print("default graph attributes")
36 print(X.graph)
37 print("node node attributes")
38 print(X.nodes.data(True))