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