我现在正在尝试可视化我在 Python 中创建的图表。但是,一旦我应用 pygraphviz,我就会得到一个错误:
A=pygraphviz.AGraph(name=N.name,strict=strict,directed=directed)
File "/usr/lib/pymodules/python2.7/pygraphviz/agraph.py", line 177, in __init__
self.handle=gv.agraphnew(name.encode(self.encoding),
AttributeError: 'Graph' object has no attribute 'encode'
我的错误在哪里?
这是代码的相应部分:
import networkx as nx
import itertools
from itertools import combinations
from networkx import *
import pygraphviz as pgv
def blocks(n):
nodes = com[n]
edges = combinations(nodes, 2)
g = nx.Graph()
g.add_nodes_from(nodes)
g.add_edges_from(edges)
return g
s=blocks(0)
A=to_agraph(s)
A.layout()
A.draw("network.ps")
然而,在测试这个时,我检查了是否可以使用 pygraphviz 绘制任何其他图表。他们可以。只需键入以下内容:
import networkx as nx
from networkx import *
import pygraphviz as pgv
G=nx.complete_graph(5)
A=to_agraph(s)
A.layout()
A.draw("network.ps")
我得到了一张完整的图表。我该怎么做才能完成这项工作?非常感谢您提前!