Graphviz 无法识别图形边缘/边缘标签被覆盖
我已将问题简化为以下简单示例:Graphviz 无法识别图形边缘/边缘标签被覆盖,graphviz,overlap,rank,dot,subgraph,Graphviz,Overlap,Rank,Dot,Subgraph,我已将问题简化为以下简单示例: digraph { subgraph {rank=same; 0 -> 1 -> 2;} 0 -> 2 [label="A"]; 2 -> 0 [label="B"]; } 产生 虽然将0、1和2保持在相同的秩中(原始示例是在一个较大图形的上下文中),但我需要a和B边是可识别的。i、 e.边缘与标签清晰匹配,标签可读 我设想的一个解决方案是使用 0:ne -> 2:nw [label="A"]; 2:sw -> 0:se [
digraph {
subgraph {rank=same; 0 -> 1 -> 2;}
0 -> 2 [label="A"];
2 -> 0 [label="B"];
}
产生
虽然将0、1和2保持在相同的秩中(原始示例是在一个较大图形的上下文中),但我需要a和B边是可识别的。i、 e.边缘与标签清晰匹配,标签可读
我设想的一个解决方案是使用
0:ne -> 2:nw [label="A"];
2:sw -> 0:se [label="B"];
然而,这产生了
其他想法?我正在生成具有相同问题的较大图形,因此最好的解决方案不是完全临时手动放置边/标签
编辑:生成的较大图形的一个(仍然简化)示例如下
digraph {
size = "6,8.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [label="4: 0.1304"];
0 -> 3 [label="5: 0.1551"];
0 -> 2 [label="7: 0.1489"];
0 -> 1 [label="Z: 0.3893"];
4 -> 0 [label="6: 0.1237"];
4 -> 3 [label="5: 0.05201"];
4 -> 2 [label="7: 0.15 "];
4 -> 1 [label="Z: 0.4585"];
3 -> 0 [label="6: 0.1658"];
3 -> 4 [label="4: 0.13 "];
3 -> 3 [label="5: 0.1038"];
3 -> 2 [label="7: 0.1616"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [label="6: 0.1661"];
2 -> 4 [label="4: 0.1295"];
2 -> 3 [label="5: 0.2078"];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103"];
1 -> 4 [label="4: 0.2591"];
1 -> 3 [label="5: 0.1382"];
1 -> 2 [label="7: 0.08581"];
1 -> 1 [label="Z: 0.1906"];
}
这将产生:
在上面的简单示例中,它显示了相同的边缘/标签重叠问题
其他说明:
- 当在同一秩子图中的双向连接的节点对中存在节点时,存在这个问题。这可能是发现bug的条件的子集
- 无向图也存在这个问题
dir=“both”
和一个
结果如下:
我必须使用
labelDistance
来防止在箭头顶部绘制“A”标签。不幸的是,我不知道如何分别更改头部标签和尾部标签的字体颜色,以便更清楚地知道哪个标签适用于哪个箭头。第一个示例显然是一个bug;边缘标签应放置在单独的位置,这样可以分离边缘。(通常,我们知道平边代码中存在漏洞,特别是在处理标签时。)一种解决方法是将部分或所有边标签视为外部标签:
digraph {
subgraph {rank=same; 0 -> 1 -> 2;}
0 -> 2 [xlabel="A"];
2 -> 0 [xlabel="B"];
}
关于上一个答案中提到的更改标签字体颜色的问题,可以使用类似HTML的标签:
0 -> 2 [dir="both", color="black:gray", labeldistance="2",
headlabel=<<font color="red">A</font>>, taillabel="B"];
0->2[dir=“两者”,color=“黑色:灰色”,labeldistance=“2”,
海岬标签=,taillabel=“B”];
这可以用于任何文本,而不是通常的双引号字符串。这两个字符串的答案都非常有用,并已被升级。(谢谢你们两位!)
我将两者的观点结合起来,以更复杂的形式回答这个问题。我仍然不觉得这个解决方案是完美的,但它是迄今为止我能产生的最好的解决方案。在这方面有所改进的未来答案(见下文,了解似乎仍然缺乏的内容)以及以自动化方式解决更大图形版本(见问题)的答案将被接受来代替此答案
首先,概括地说,迄今为止最好的解决方案是:将一些边(例如,随机选择的所有双向边的一半)的标签转换为XLabel,并随机为边和相应的标签上色(通过fontcolor
)
具体而言,这里是此解决方案的一个实例,其中边随机为红色、绿色或黑色:
digraph {
size = "6,10.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [xlabel="4: 0.1304" color=blue fontcolor=blue];
0 -> 3 [xlabel="5: 0.1551" color=green fontcolor=green];
0 -> 2 [label="7: 0.1489" color=red fontcolor=red];
0 -> 1 [label="Z: 0.3893"];
4 -> 0 [xlabel="6: 0.1237" color=green fontcolor=green];
4 -> 3 [xlabel="5: 0.05201 " color=green fontcolor=green];
4 -> 2 [xlabel="7: 0.15" color=blue fontcolor=blue];
4 -> 1 [label="Z: 0.4585" color=red fontcolor=red];
3 -> 0 [xlabel="6: 0.1658"];
3 -> 4 [xlabel="4: 0.13" color=red fontcolor=red];
3 -> 3 [label="5: 0.1038" color=blue fontcolor=blue];
3 -> 2 [xlabel="7: 0.1616"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [label="6: 0.1661" color=blue fontcolor=blue];
2 -> 4 [xlabel="4: 0.1295" color=red fontcolor=red];
2 -> 3 [label="5: 0.2078" color=green fontcolor=green];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103" color=red fontcolor=red];
1 -> 4 [label="4: 0.2591" color=blue fontcolor=blue];
1 -> 3 [label="5: 0.1382" color=green fontcolor=green];
1 -> 2 [label="7: 0.08581 "];
1 -> 1 [label="Z: 0.1906"];
}
这将产生:
这仍然不完全令人满意,因为:
- 使每个标签都成为xlabel。结果:所有内容都被压缩,标签相互重叠和模糊
- 对所有双向边使用xlabel。结果:与上述问题相同
- 使用不带颜色的XLabel。结果:很难追踪哪个标签属于什么
- 使用ssteve的
+颜色列表。对边缘随机着色。并将头标签和尾标签的dir=“两者”
随机设置为3到11之间,以避免节点处的标签重叠。结果:这很难自动化,仍然会导致边缘标签重叠和标签难以追溯到它们对应的边缘。(见下文)labeldistance
size = "6,8.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [dir="both", color="yellow:blue", labeldistance="5", headlabel=<<font color="yellow">4: 0.1304</font>>, taillabel=<<font color="blue">6: 0.1237</font>>];
0 -> 3 [dir="both", color="blue:black", labeldistance="8", headlabel=<<font color="blue">5: 0.1551</font>>, taillabel=<<font color="black">6: 0.1658</font>>];
0 -> 1 [label="Z: 0.3893"];
4 -> 1 [label="Z: 0.4585"];
3 -> 4 [dir="both", color="green:red", labeldistance="5", headlabel=<<font color="green">4: 0.13</font>>, taillabel=<<font color="red">5: 0.05201</font>>];
3 -> 3 [label="5: 0.1038"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [dir="both", color="yellow:blue", labeldistance="11", headlabel=<<font color="yellow">6: 0.1661</font>>, taillabel=<<font color="blue">7: 0.1489</font>>];
2 -> 4 [dir="both", color="black:red", labeldistance="5", headlabel=<<font color="black">4: 0.1295</font>>, taillabel=<<font color="red">7: 0.15</font>>];
2 -> 3 [dir="both", color="blue:green", labeldistance="8", headlabel=<<font color="blue">5: 0.2078</font>>, taillabel=<<font color="green">7: 0.1616</font>>];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103"];
1 -> 4 [label="4: 0.2591"];
1 -> 3 [label="5: 0.1382"];
1 -> 2 [label="7: 0.08581 "];
1 -> 1 [label="Z: 0.1906"];
}
size=“6,8.5”;
比率=“填充”;
节点[形状=圆];
节点[fontsize=24];
边[fontsize=24];
{图[rank=same];边[color=invi];1;}
{图[rank=same];边[color=invi];2->0->3->4;}
0->0[label=“6:0.1764”];
0->4[dir=“both”、color=“yellow:blue”、labeldistance=“5”、headbel=、taillabel=];
0->3[dir=“both”、color=“blue:black”、labeldistance=“8”、headbel=、taillabel=];
0->1[label=“Z:0.3893”];
4->1[label=“Z:0.4585”];
3->4[dir=“both”、color=“green:red”、labeldistance=“5”、headbel=、taillabel=];
3->3[label=“5:0.1038”];
3->1[label=“Z:0.4388”];
2->0[dir=“两者”,color=“黄色:蓝色”,labeldistance=“11”,headbel=,taillabel=”;
2->4[dir=“both”、color=“black:red”、labeldistance=“5”、headbel=、taillabel=];
2->3[dir=“both”,color=“blue:green”,labeldistance=“8”,headbel=,taillabel=];
2->2[label=“7:0.1406”];
2->1[label=“Z:0.356”];
1->0[label=“6:0.1103”];
1->4[label=“4:0.2591”];
1->3[label=“5:0.1382”];
1->2[label=“7:0.08581”];
1->1[label=“Z:0.1906”];
}
这将产生:
征求其他意见/改进
size = "6,8.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [dir="both", color="yellow:blue", labeldistance="5", headlabel=<<font color="yellow">4: 0.1304</font>>, taillabel=<<font color="blue">6: 0.1237</font>>];
0 -> 3 [dir="both", color="blue:black", labeldistance="8", headlabel=<<font color="blue">5: 0.1551</font>>, taillabel=<<font color="black">6: 0.1658</font>>];
0 -> 1 [label="Z: 0.3893"];
4 -> 1 [label="Z: 0.4585"];
3 -> 4 [dir="both", color="green:red", labeldistance="5", headlabel=<<font color="green">4: 0.13</font>>, taillabel=<<font color="red">5: 0.05201</font>>];
3 -> 3 [label="5: 0.1038"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [dir="both", color="yellow:blue", labeldistance="11", headlabel=<<font color="yellow">6: 0.1661</font>>, taillabel=<<font color="blue">7: 0.1489</font>>];
2 -> 4 [dir="both", color="black:red", labeldistance="5", headlabel=<<font color="black">4: 0.1295</font>>, taillabel=<<font color="red">7: 0.15</font>>];
2 -> 3 [dir="both", color="blue:green", labeldistance="8", headlabel=<<font color="blue">5: 0.2078</font>>, taillabel=<<font color="green">7: 0.1616</font>>];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103"];
1 -> 4 [label="4: 0.2591"];
1 -> 3 [label="5: 0.1382"];
1 -> 2 [label="7: 0.08581 "];
1 -> 1 [label="Z: 0.1906"];
}