gpt4 book ai didi

python - 防止边穿过pygraphviz中的节点

转载 作者:太空宇宙 更新时间:2023-11-04 07:36:32 27 4
gpt4 key购买 nike

我正在读取一个 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)

图形很复杂,但我真的更希望边不穿过节点。我试过,当我设置严格和重叠时,但我仍然有线穿过节点。

Graph with crossed nodes

这似乎是人们经常遇到的东西,但我找不到任何关于它的东西。我可能做错了什么,或者使用了错误的搜索词。任何帮助表示赞赏。

最佳答案

发生这种情况是因为 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')

关于python - 防止边穿过pygraphviz中的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33817811/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com