我正在读取一个 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)
图形很复杂,但我真的更希望边不穿过节点。我试过,当我设置严格和重叠时,但我仍然有线穿过节点。
这似乎是人们经常遇到的东西,但我找不到任何关于它的东西。我可能做错了什么,或者使用了错误的搜索词。任何帮助表示赞赏。
请您参考如下方法:
发生这种情况是因为 splines attribute图形化。
By default, the attribute is unset. How this is interpreted depends on the layout. For dot, the default is to draw edges as splines. For all other layouts, the default is to draw edges as line segments. Note that for these latter layouts, if splines="true", this requires non-overlapping nodes (cf. overlap). If fdp is used for layout and splines="compound", then the edges are drawn to avoid clusters as well as nodes.
将其作为命名参数提供应该可以解决问题:
trial = pgv.AGraph(strict=False, overlap=False, splines='true')
#or
trial = pgv.AGraph(strict=False, overlap=False, splines='spline')
