This question is about attempting to model interdependent networks with NetworkX. There are dedicated packages (such as Pymnet), but they don't seem as flexible as NetworkX. And by the way, I wanted to give NetworkX one last chance.
So, let's say we have 2 separate graphs, G1 and G2, which we plot in the same figure:
import networkx as nx
import matplotlib.pyplot as plt
G1=nx.barabasi_albert_graph(3, 2) #n=3, m=2 (number of initial links)
G2=nx.barabasi_albert_graph(3, 2)
pos1=nx.spring_layout(G1)
pos2=nx.spring_layout(G2)
nx.draw_networkx(G1,pos=pos1,node_color='red') #G1 is red
nx.draw_networkx(G2,pos=pos2,node_color='green') #G2 is green
Now, if we attempt to connect node 0 of G1 with node 1 of G2:
G1.add_edge(G1.nodes()[0], G2.nodes()[1])
we don't get any error, but if you plot the graphs again, the image is exactly as before. And if you check the number of edges you get the same results as before:
In[17]: G1.edges()
Out[17]: [(0, 1), (0, 2), (1, 2)]
In[18]: G2.edges()
Out[18]: [(0, 2), (1, 2)]
meaning that the edge was basically not added, or it was added and is not displayed, or it was added, but because it runs from one graph to another, it doesn't belong to any of them.
How do you suggest to create this interconnection from G1 to G2 in NetworkX, without resorting to other packages?