Combine (join) networkx Graphs
问题 Say I have two networkx graphs, G and H : G=nx.Graph() fromnodes=[0,1,1,1,1,1,2] tonodes=[1,2,3,4,5,6,7] for x,y in zip(fromnodes,tonodes): G.add_edge(x,y) H=nx.Graph() fromnodes=range(2,8) tonodes=range(8,14) for x,y in zip(fromnodes,tonodes): H.add_edge(x,y) What is the best way to join the two networkx graphs? I'd like to preserve the node names (note the common nodes, 2 to 7). When I used nx.disjoint_union(G,H) , this did not happen: >>> G.nodes() [0, 1, 2, 3, 4, 5, 6, 7] >>> H.nodes() [2