如何在python中添加networkx中的重复节点

时间:2017-06-30 08:32:55

标签: python networkx

我想在python中的networkx上绘制数据帧中的每一行,但由于同一个节点出现两次,它被覆盖是否有任何方法我可以避免覆盖。任何帮助都会有很大的帮助,提前谢谢 这是我在python中绘制networkx的代码

我的代码

i = 0
for j in abc:
    G.add_edge(abc[i][0],abc[i][1],weight = abc[i][6])
    G.add_edge(abc[i][1],abc[i][2],weight = abc[i][6])
    G.add_edge(abc[i][2],abc[i][3],weight = abc[i][6])
    i = i + 1

from pylab import rcParams
rcParams['figure.figsize'] = 12, 12

elarge=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] >0.10]
emed=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] >0.05 and d['weight'] <0.10]
esmall=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] <0.05]


pos=nx.spring_layout(G) # positions for all nodes

edge_labels = nx.get_edge_attributes(G,'weight')

# nodes
nx.draw_networkx_nodes(G,pos,node_size=3000,node_color= "grey")



# edges
nx.draw_networkx_edges(G,pos,edgelist=elarge,
                    width=2,alpha = 0.5,edge_color = "b",style = "dashed",edge_labels = edge_labels)

nx.draw_networkx_edges(G,pos,edgelist=esmall,
                    width=3,alpha=0.5,edge_color='r',style='dashed')
nx.draw_networkx_edges(G,pos,edgelist=emed,
                    width=3,alpha=0.2,edge_color='g',style='dashed')

nx.draw_networkx_edge_labels(G,pos,font_size= 12,font_family = "sans-serif")


# labels
nx.draw_networkx_labels(G,pos,font_size=12,font_family='sans-serif')
plt.axis('on')
plt.savefig("/home/hduser/Desktop/weighted_graph.png") # save as png
plt.show()
plt.close# displayelarge=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] >0.10]
emed=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] >0.05 and d['weight'] <0.10]
esmall=[(u,v) for (u,v,d) in G.edges(data=True) if d['weight'] <0.05]


pos=nx.spring_layout(G) # positions for all nodes

edge_labels = nx.get_edge_attributes(G,'weight')

# nodes
nx.draw_networkx_nodes(G,pos,node_size=3000,node_color= "grey")



# edges
nx.draw_networkx_edges(G,pos,edgelist=elarge,
                    width=2,alpha = 0.5,edge_color = "b",style = "dashed",edge_labels = edge_labels)

nx.draw_networkx_edges(G,pos,edgelist=esmall,
                    width=3,alpha=0.5,edge_color='r',style='dashed')
nx.draw_networkx_edges(G,pos,edgelist=emed,
                    width=3,alpha=0.2,edge_color='g',style='dashed')

nx.draw_networkx_edge_labels(G,pos,font_size= 12,font_family = "sans-serif")


# labels
nx.draw_networkx_labels(G,pos,font_size=12,font_family='sans-serif')
plt.axis('on')
plt.savefig("/home/hduser/Desktop/weighted_graph.png") # save as png
plt.show()
plt.close# displayre

dataframe which i am converting to list and then adding its elements to G.add_edge

My networkx output

0 个答案:

没有答案