I am using python, NetworkX and Matplotlib, I want to connect same node from two graphs For example two graphs:G1 and G2
G1=nx.Graph()
G2=nx.Graph()
G1.add_nodes_from([0,1,2,3,9,8,10,11,12,13,14])
G2.add_nodes_from([4,5,6,7,8])
G1.add_edges_from([(0,1),(2,3),(2,9),(2,12),(1,9),(10,8),(8,11),(8,13),(8,14)])
G2.add_edges_from([(4,5),(6,7),(4,8)])
pos1=nx.spring_layout(G1,k=0.2,iterations=30)
pos2=nx.spring_layout(G2)
for k,v in pos2.items():
v[0] = v[0] +3
nx.draw(G1,pos1,with_labels=True,node_color='b')
nx.draw(G2,pos2,with_labels=True)
The image is like this:
My question is how can I connect the same nodes from two graphs? (node "8" is in both of them)
I want node"8"(blue) link with node"8"(red).
I also used G3= nx.compos(G1,G2), but I don't know how to draw the nodes(color =blue,from G1) at the right side and the other nodes at the left side(color =red, from G2). So I gave up this method.