node_attribute_xy#
- node_attribute_xy(G, attribute, nodes=None)[源代码]#
为
G
中的所有边生成节点属性值的 2 元组。此生成器为
G
中与nodes
中节点关联的每条边生成一个 2 元组,其形式为(attribute value, attribute value)
,对应于参数指定的节点属性。- 参数:
- G: NetworkX 图
- attribute: 键
节点属性键。
- nodes: list 或 iterable(可选)
仅使用与指定节点关联的边。默认为所有节点。
- 生成:
- (x, y): 2 元组
生成 (attribute, attribute) 值的 2 元组。
注意
对于无向图,每条边会生成两次,一次表示 (u, v),一次表示 (v, u),但自环边除外,自环边只出现一次。
示例
>>> 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')]