我有以下图表,可以删除和添加节点、边。
最终的输出结果没有排序,以下是节点编号(属性也没有排序)
我想知道如何创建一个排序图表。
import networkx as nx
import matplotlib.pyplot as plt
G = nx.gnm_random_graph(n=10, m=15, seed=1)
pos = nx.spring_layout(G)
print(pos)
nx.set_node_attributes(G, pos, 'pos')
G.remove_edge(2, 9)
largest_cc = max(nx.connected_components(G), key=len)
G = G.subgraph(largest_cc).copy()
G.add_node(2, pos=pos[2])
G.add_edge(2, 8)
print(G.edges)
print(nx.get_node_attributes(G, 'pos'))
print(G.nodes)
最终的输出结果没有排序,以下是节点编号(属性也没有排序)
print(G.nodes)
[0, 1, 3, 4, 5, 6, 7, 8, 9, 2]
期望输出:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
我想知道如何创建一个排序图表。
sorted(G.nodes)
而不将节点复制到新图中? - undefined