我现在正在尝试可视化我在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")
我获得了完整图表的图纸。 我能做些什么来完成这项工作?非常感谢你提前完成!