我正在读取一个 JSON 文件并使用 pygraphviz 动态创建一个图形,使用一个简单的循环:
hostdata = []
nodes = []
edges = {}
current_host = ""
trial = pgv.AGraph(strict=False, overlap=False)
for filename in os.listdir(options.directory):
with open(options.directory + "/" + filename, "r") as myfile:
hostdata = Truth(myfile.read().replace('\n', ''))
nodes.append(hostdata.host["something"])
current_something = hostdata.host["something"]
for key, value in hostdata.peer.iteritems():
nodes.append(key)
edges[current_something] = key
trial.add_edge(current_host, key)
该图很复杂,但如果边不跨越节点,我真的更喜欢。我试过了,当我设置严格和重叠时,我仍然有跨越节点的线。
这似乎是人们经常遇到的事情,但我在上面找不到任何东西。我可能做错了什么,或者使用了错误的搜索词。任何帮助表示赞赏。