Graphviz 不必要的长边/节点之间的距离

问题描述 投票:0回答:2

我有一棵用 Graphviz 绘制的树,但是节点之间的距离非常大并且没有得到有效利用。这可以改进吗?

我尝试使用

mindist
splines
overlap
,但似乎没有任何效果。这是 graphviz 能做到的最好的吗?

数据:

https://pastebin.com/JUC7GhLV

代码:

import json
import pygraphviz as pgv
# Read data from the "graph1.json" file
with open("graph2.json") as f:
    edges_data = json.load(f)

# Create a new directed graph
graph = pgv.AGraph(strict=False, directed=True)

# Add nodes and edges to the graph based on the JSON data
for edge in edges_data:
    graph.add_node(edge["ID"])
    if edge["ParentID"]:
        graph.add_edge(edge["ParentID"], edge["ID"])

graph_attrs = {
    'dpi': 50, 
    'root': 10000185, 
    'mindist': 0.1
#    'splines': False,   # false 
#    'overlap':'scale'    # false
}

graph.graph_attr.update(graph_attrs)
graph.draw("output_graph.svg", prog="circo", format="svg")
graphviz graph-visualization pygraphviz
2个回答
1
投票

您可能遇到了这个circo错误:

尝试找到circo解决方法可能不会成功(除非你感觉幸运)
尝试其他布局引擎,twopineatofdpdot


1
投票

边长属性

Graphviz 具有属性

len
:

首选边缘长度,以英寸为单位

但是:

注意:neato,仅限 fdp。

另请参阅:如何在 graphviz 中指定边的长度?.

以 2 英寸为例

因此,您可以添加:

graph.edge_attr["len"] = 2  # Preferred edge length, in inches, works only with layout-engines neato or fdp
graph.draw("output_graph.png", prog="neato")

设置首选边长为 2 英寸,neato 引擎渲染的给定 4973 个节点的输出变成难以辨认、重叠的雪花,如下图所示:

以 4 英寸为例

再次尝试 4 英寸产生:

注意:渲染时间更长,文件大小也从 2 英寸 PNG 的 2.2M 增加到 15M。

以 6 英寸为例

边长 6 英寸,文本仍然无法阅读:

现在 PNG 已达到 22M。

© www.soinside.com 2019 - 2024. All rights reserved.