gpt4 book ai didi

graphviz - 在 Graphviz 中的子图下添加标签

转载 作者:行者123 更新时间:2023-12-04 04:33:55 26 4
gpt4 key购买 nike

我使用以下代码在 Graphviz 中使用点生成图形。我手动包含了节点的坐标,因为我需要四个不相交的子图彼此相邻放置,如图所示。
ss

我想在每个子图下添加标签:$G_0$、$G_1$ 等。在子图下添加标签会创建一个框并忽略我的坐标对齐。有没有其他方法,比如在指定坐标处放置任意文本?我使用“dot -Teps -Kfdp -n tree -o t.eps”进行编译。

digraph Trees {
node [shape=circle, style="filled", fixedsize=true,width=0.6]; 0; 1;2; 3;4; 5;6; 7; 8;9;10;11;12;13;14;15;
0[pos = "0,1!"]
1[fillcolor=red, pos = "-1,2!"]
2[pos = "1,2!"]
3 [pos = "0,-0.5!"]
5[label=1, fillcolor=red, pos = "2,2!"]
4[label=0, fillcolor=red, pos = "3,1!"]
6[label=2, pos = "4,2!"]
7[label=3, pos = "3, -0.5!"]
9[label=1, fillcolor=red, pos = "5,2!"]
8[label=0, fillcolor=red, pos = "6,1!"]
10[label=2, pos = "7,2!"]
11[label=3, fillcolor=red, pos = "6, -0.5!"]
12[label=1, fillcolor=red, pos = "8,2!"]
13[label=0, fillcolor=green, pos = "9,1!"]
14[label=2, pos = "10, 2!"]
15[label=3, fillcolor=green, pos = "9, -0.5!"]

overlap=false;
fontsize=10;

subgraph 1{
edge [dir=none] 1->0 2->0 3->0;
}

subgraph 2{
edge [color=red] 5->4;
edge[color=black, dir=none] 6->4 7->4;
}

subgraph 3{
edge [color=red] 9->8 8->11;
edge [color=black, dir=none] 8->10;
}

subgraph 4{
edge [color=green] 12->13; 13->15;
edge [color=black, dir=none] 13->14;
}
}

最佳答案

可以使用集群和点布局引擎使子图不相交。同样的方法也将允许引入集群标签。它们可以根据需要放置在集群的底部,而无需创建虚拟节点。

这样就不需要绝对位置,而且即使添加了其他节点也会自动生成布局。节点的确切位置发生了变化,但图的拓扑结构保持不变。

digraph Trees { node [shape = circle, style = "filled", fixedsize = true, width=0.4]; 
edge [dir = none];
layout = dot; overlap = false; fontsize = 10;
graph [labelloc = "b", penwidth = 0];
{ node [fillcolor = "red"];
1; 5 [label = 1]; 4 [label = 0]; 9 [label = 1];
8 [label = 0]; 11 [label = 3]; 12 [label = 1];
}

2; 0; 3; 6 [label = 2]; 7 [label = 3];
10 [label = 2]; 14 [label = 2];
{ node [fillcolor = "green"];
13 [label = 0]; 15 [label = 3];
}
subgraph cluster1{
label = "Subgraph 1";
{ 1; 2; } -> 0 -> 3;
}
subgraph cluster2{
label = "Subgraph 2";
5 -> 4 [color = red, dir = fwd];
6 -> 4 -> 7;
}
subgraph cluster3{
label = "Subgraph 3";
9 -> 8-> 11 [color=red, dir = fwd];
10 -> 8 [color=black];
}
subgraph cluster4{
label = "Subgraph 4";
12 -> 13 -> 15 [color=green, dir = fwd];
14-> 13;
}
}

The Dot generated layout

关于graphviz - 在 Graphviz 中的子图下添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20094502/

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