node_attribute_xy#
- node_attribute_xy(G, attribute, nodes=None)[source]#
Yields 2-tuples of node attribute values for all edges in
G
.This generator yields, for each edge in
G
incident to a node innodes
, a 2-tuple of form(attribute value, attribute value)
for the parameter specified node-attribute.- Parameters:
- G: NetworkX graph
- attribute: key
The node attribute key.
- nodes: list or iterable (optional)
Use only edges that are incident to specified nodes. The default is all nodes.
- Yields:
- (x, y): 2-tuple
Generates 2-tuple of (attribute, attribute) values.
Notes
For undirected graphs, each edge is produced twice, once for each edge representation (u, v) and (v, u), with the exception of self-loop edges which only appear once.
Examples
>>> G = nx.DiGraph() >>> G.add_node(1, color="red") >>> G.add_node(2, color="blue") >>> G.add_node(3, color="green") >>> G.add_edge(1, 2) >>> list(nx.node_attribute_xy(G, "color")) [('red', 'blue')]