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),
要放在最后面,而且要多加个逗号,不然出错。
