Hope my question has not asked before. I have two graphs, which nodes are the same in both of them but edges are different. I want to draw both of graphs in one plot. Which means I have the same nodes, but with two different edge colours. But it gives me two different graphs. How could I have them in one graph but with different edge colours?
views:
30answers:
1
+1
A:
If you are using Python, NetworkX and Matplotlib then you can do something like this, where you have two graphs with the same set of nodes and so you draw first the nodes and then the two set of edges in different colors.
import networkx as nx
G=nx.gnm_random_graph(10,20)
G2=nx.gnm_random_graph(10,20)
pos=nx.spring_layout(G)
nx.draw_networkx_nodes(G,pos,node_size=80)
nx.draw_networkx_edges(G,pos,edge_color='r')
nx.draw_networkx_edges(G2,pos,edge_color='b')
Take care with edges of different colors between the same endpoints, they will be indistinguishable.
thetarro
2010-09-24 15:53:26