2017-08-16 20 views
0

Iは、ノードの色をプロットするために、次のコードを行い、ファイルからカラーマップエッジた:同じグラフ上の2つの異なるエッジカラーマップ?

## 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]) 

をしかし、私は種類ごとに異なる可能な重みと、ノード間の可能な接続の2つの種類を持っているので、私は希望エッジのために2つの異なるカラーマップを使用してグラフをプロットします。何か問題はありますか?

ありがとうございます!

答えて

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) 
関連する問題