【问题标题】:Preventing edges from crossing nodes in pygraphviz防止边缘在pygraphviz中穿过节点
【发布时间】:2016-02-22 10:00:44
【问题描述】:

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

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

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

【问题讨论】:

  • 您始终可以将图形保存为字符串并使用dot (example) 进行渲染

标签: python pygraphviz


【解决方案1】:

这是因为 graphviz 的splines attribute

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

将其作为命名参数提供应该可以解决问题:

trial = pgv.AGraph(strict=False, overlap=False, splines='true')
#or   
trial = pgv.AGraph(strict=False, overlap=False, splines='spline')

【讨论】:

  • 谢谢!由于我得到的关注很少,我开始认为也许人们只是忍受了这一点。现在我在文档中看到了它,但很明显。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-09
  • 2018-02-12
  • 2018-03-11
  • 1970-01-01
  • 2019-04-13
  • 2021-12-14
  • 1970-01-01
相关资源
最近更新 更多