使用网络绘制图形

时间:2016-12-02 10:01:44

标签: python-2.7

这是我的代码:

import networkx as nx
import matplotlib.pyplot as plt

fh =open('one.txt', 'r')
G=nx.read_edgelist(fh, nodetype=int)
fh.close()

print nx.info(G)
nx.draw(G)
plt .show()

但使用它我会收到以下错误:

Traceback (most recent call last):   File "graphDeBruijn.py", line 5, 
in <module>     G=nx.read_edgelist(fh, nodetype=int)   File "<decorator-gen-286>", line 2, 
in read_edgelist   File "C:\PYTHON27\lib\site-packages\networkx-2.0.dev20161201181419-py2.7.egg\networkx\utils\decorators.py", line 221, 
in _open_file     result = func(*new_args, **kwargs)   File "C:\PYTHON27\lib\site-packages\networkx-2.0.dev20161201181419-py2.7.egg\networkx\readwrite\edgelist.py", line 374, 
in read_edgelist     data=data)   File "C:\PYTHON27\lib\site-packages\networkx-2.0.dev20161201181419-py2.7.egg\networkx\readwrite\edgelist.py", line 255, 
in parse_edgelist     for line in lines:   File "C:\PYTHON27\lib\site-packages\networkx-2.0.dev20161201181419-py2.7.egg\networkx\readwrite\edgelist.py", line 371, 
in <genexpr>     lines = (line.decode(encoding) for line in path)   File "C:\PYTHON27\lib\encodings\utf_8.py", line 16, 
in decode     return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte

任何人都可以帮助我吗?谢谢!

0 个答案:

没有答案