File: plot_attributes.py

package info (click to toggle)
networkx 3.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,700 kB
  • sloc: python: 105,310; xml: 544; makefile: 131; javascript: 120; sh: 34
file content (28 lines) | stat: -rw-r--r-- 694 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Attributes
==========

Example illustrating how attributes of nodes, edges, and graphs are handled
during conversion to/from `~pygraphviz.AGraph`.
"""

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)  # convert to a graphviz graph
A.draw("attributes.png", prog="neato")  # Draw with pygraphviz

# 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))