python networkx教程_如何在python中使用networkx绘制有向图?
我只是為了完整而把它放進去 . 我從marius和mdml中學到了很多東西 . 這是邊緣權重 . 抱歉箭頭 . 看起來我不是唯一一個說它無法幫助的人 . 我無法使用ipython筆記本呈現這一點我不得不直接從python直接獲得我的邊緣權重的問題 .
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
import pylab
G = nx.DiGraph()
G.add_edges_from([('A', 'B'),('C','D'),('G','D')], weight=1)
G.add_edges_from([('D','A'),('D','E'),('B','D'),('D','E')], weight=2)
G.add_edges_from([('B','C'),('E','F')], weight=3)
G.add_edges_from([('C','F')], weight=4)
val_map = {'A': 1.0,
'D': 0.5714285714285714,
'H': 0.0}
values = [val_map.get(node, 0.45) for node in G.nodes()]
edge_labels=dict([((u,v,),d['weight'])
for u,v,d in G.edges(data=True)])
red_edges = [('C','D'),('D','A')]
edge_colors = ['black' if not edge in red_edges else 'red' for edge in G.edges()]
pos=nx.spring_layout(G)
nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_labels)
nx.draw(G,pos, node_color = values, node_size=1500,edge_color=edge_colors,edge_cmap=plt.cm.Reds)
pylab.show()
總結
以上是生活随笔為你收集整理的python networkx教程_如何在python中使用networkx绘制有向图?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天涯er告诉我我到底要不要去开眼角?[已
- 下一篇: 中国好声音歌手姚贝娜乳腺癌复发昏迷了,是