gpt4 book ai didi

Graphviz 节点的点垂直对齐

转载 作者:行者123 更新时间:2023-12-03 14:34:25 31 4
gpt4 key购买 nike

我得到了这个点图,并希望节点 A 和 D、B 和 E 以及 C 和 F 对齐。这是相关的点代码:

digraph{

A
B
C
D
E
F

{rank = same; B; C}
{rank = same; E; F}

A -> B [label="2", weight=2]
A -> C [label="0", style=dashed, weight=2]
B -> C [label="0", style=dashed, weight=2]
B -> D [label="2", style=dashed, weight=2]
C -> D [label="0", weight=2]
D -> E [label="1", style=dashed, weight=2]
D -> F [label="0", weight=2]
E -> F [label="0", weight=2]
F -> A
}

如您所见,我已经尝试将权重应用于边缘,但没有成功

enter image description here

最佳答案

可以使用 group节点的属性,建议将同一组的节点之间的边沿直线对齐。
使用 group 属性声明节点:

A [group=g1]
{rank = same; B[group=g2]; C[group=g3]}
D [group=g1]
{rank = same; E[group=g2]; F[group=g3]}
然后确保所有这些节点之间都有(不可见的)边:
edge[style=invis];
A -> D
B -> E
C -> F
一切都在一起:
digraph G {
A [group=g1]
{rank = same; B[group=g2]; C[group=g3]}
D [group=g1]
{rank = same; E[group=g2]; F[group=g3]}

A -> B [label="2", weight=2]
A -> C [label="0", style=dashed, weight=2]
B -> C [label="0", style=dashed, weight=2]
B -> D [label="2", style=dashed, weight=2]
C -> D [label="0", weight=2]
D -> E [label="1", style=dashed, weight=2]
D -> F [label="0", weight=2]
E -> F [label="0", weight=2]
F -> A

edge[style=invis];
A -> D
B -> E
C -> F
}
Graphviz diagram

关于Graphviz 节点的点垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27091591/

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