python库之networkx之创建有向图的方法

import networkx as nx
import matplotlib.pyplot as plt
 
textline = '1 2 3'
fh = open('test.edgelist','w')
d = fh.write(textline)
fh.close()
G = nx.read_edgelist('test.edgelist', create_using=nx.DiGraph(),nodetype=int, data=(('weight',float),))
nx.draw(G)
plt.show()

结果如下:

其中

data=(('weight',float),

要放在最后面,而且要多加个逗号,不然出错。

posted on 2020-09-29 22:27  Mint-Tremor  阅读(1120)  评论(0编辑  收藏  举报

导航