防止边缘穿过pygraphviz中的节点

Bil*_*mpf 1 python pygraphviz

我正在阅读一个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)
Run Code Online (Sandbox Code Playgroud)

图表很复杂,但我真的更喜欢边缘不跨越节点.我试过,当我设置严格和重叠时,但我仍然有越过节点的线.

带有交叉节点的图形

这似乎是人们会碰到的东西,但我找不到任何东西.我可能做了一些完全错误的事情,或使用了错误的搜索词.任何帮助赞赏.

rll*_*rll 7

这是因为graphviz 的splines属性而发生的.

默认情况下,该属性未设置.如何解释这取决于布局.对于点,默认设置是将边绘制为样条曲线.对于所有其他布局,默认设置是将边绘制为线段.请注意,对于后面这些布局,如果splines ="true",则需要非重叠节点(参见重叠).如果fdp用于布局并且splines ="compound",则绘制边以避免簇和节点.

将它作为命名参数提供应解决问题:

trial = pgv.AGraph(strict=False, overlap=False, splines='true')
#or   
trial = pgv.AGraph(strict=False, overlap=False, splines='spline')
Run Code Online (Sandbox Code Playgroud)