&#34; TypeError:&#39;在<string>&#39;需要字符串作为左操作数,而不是int&#34;使用graphviz点布局时

时间:2017-07-28 11:58:14

标签: python networkx pygraphviz

我试图使用pygraphviz&#39;使用networkX进行点布局。但我收到了错误

 File "C:\Users\msi\Anaconda3\lib\site-packages\pyparsing.py", line 1028, in preParse
    while loc < instrlen and instring[loc] in wt:
TypeError: 'in <string>' requires string as left operand, not int

可能是因为graphviz不适用于我正在使用的python 3.

这是我的代码:

import networkx as nx
import matplotlib.pyplot as plt

G=nx.DiGraph()

n = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
e = [(1,2),(1,3),(2,4),(2,5),(3,6),(3,7),
     (8,9),(8,10),(9,11),(9,12),(10,13),(10,14),(7,8)]

G.add_nodes_from(n)
G.add_edges_from(e)

pos=nx.graphviz_layout(G,prog='dot')
nx.draw(G, pos=pos, with_labels=True)
plt.show()

0 个答案:

没有答案