2017-08-16 101 views
0

我也做了下面的代碼從文件中繪製的節點和邊緣的彩色地圖顏色:兩張不同的邊緣顏色圖在同一張圖上?

## NODES COLORS## 
Active={} 
with open('NWWE/node'+str('{:03d}'.format(i))+'.txt', 'r') as f: 
    for j in f: 
     a,b=j.split(',') 
     Active[a]=b[0] 
for node in G.nodes(): 
     G.node[node]['category'] = Active[node] 
color_map = {'0':'b', '1':'r'} 

##EDGES COLOR MAP## 
with open('NWWE/edges'+str('{:03d}'.format(i))+'.txt', 'r') as f: 
    for k in f: 
     a,b,c=k.split(',') 
     G[a][b]['weight']=float(c) 

edges,weights = zip(*nx.get_edge_attributes(G,'weight').items()) 

##DRAW GRAPH## 
nx.draw(G, pos, edgelist=edges, edge_color=weights, width=5.0, edge_cmap=plt.cm.Blues, node_color=[color_map[G.node[node]['category']] for node in G]) 

但我有兩種節點之間的可能聯繫的,與各種不同的可能的權重,所以我想繪製我的圖形使用兩個不同的顏色地圖的邊緣。有什麼問題嗎?

非常感謝!

回答

0

我找到解決方案感謝nx.draw_networkx_edges

#one group with one color map : 
edges = tuple(list_edgesG1) 
weights = tuple([G[e][f]['weight'] for e,f in edges]) 
nx.draw_networkx_edges(G, pos, edgelist=edges, edge_color=weights, width=3.0, edge_cmap=plt.cm.Reds) 

#the other group with different color map : 
edges2 = tuple(list_edgesG2) 
weights2 = tuple([G[e][f]['weight'] for e,f in edges2]) 
nx.draw_networkx_edges(G , pos, edgelist=edges2, edge_color=weights2, width=3.0, edge_cmap=plt.cm.Blues) 
相關問題