"""
=====================
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))

8b42f48f644621945ed255869516991e50a02f29
<mask token>

<mask token>
G.add_edge(1, 2, color='red')
G.add_edge(2, 3, color='red')
G.add_node(3)
G.add_node(4)
<mask token>
A.write('k5_attributes.dot')
<mask token>
print('edges')
print(list(X.edges(data=True)))
print('default graph attributes')
print(X.graph)
print('node node attributes')
print(X.nodes.data(True))

<mask token>
G = nx.Graph()
G.add_edge(1, 2, color='red')
G.add_edge(2, 3, color='red')
G.add_node(3)
G.add_node(4)
A = nx.nx_agraph.to_agraph(G)
A.write('k5_attributes.dot')
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))

<mask token>
import networkx as nx
G = nx.Graph()
G.add_edge(1, 2, color='red')
G.add_edge(2, 3, color='red')
G.add_node(3)
G.add_node(4)
A = nx.nx_agraph.to_agraph(G)
A.write('k5_attributes.dot')
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))

"""
=====================
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))
