ssteve 和 emden 的回答非常有用,并得到了支持。 (谢谢你们!)
我正在整合双方的意见,并以更复杂的版本回答这个问题。我仍然不觉得这个解决方案是完美的,但它是迄今为止我能产生的最好的。将来会对此进行改进的答案(请参阅下文了解似乎仍然缺乏的内容)并以可以自动化的方式解决更大的图形版本(请参阅问题)来代替此答案。
首先,总结迄今为止最好的解决方案:将标签转换为 xlabels 用于 一些 边缘(例如,所有双向边缘的一半,随机选择)并随机着色边缘和相应的标签(通过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 时,某些标签会出现在奇怪的位置。 (例如上面的 2 -> 4 标签)
- 随机选择哪些标签成为 xlables 似乎是任意的。也没有办法(我知道)保证这总是可行的。
我尝试过的其他事情:
- 将每个标签都设为 xlabel。结果:所有内容都被压缩,标签相互重叠和模糊。
- 对所有双向边使用 xlabel。结果:与上述相同的问题。
- 使用不带颜色的 xlabels。结果:很难追踪哪个标签属于什么。
- 使用 ssteve 的
dir="both" + 颜色列表 solution。随机着色边缘。并为头尾标签随机设置labeldistance在3到11之间,以避免节点处的标签重叠。结果:这更难以自动化,并且仍然导致边缘标签重叠和标签难以追溯到它们对应的边缘。 (见下文)
这是上面“我尝试过的其他事情”解决方案列表中最后一项的示例。
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"];
}
这会产生:
征求其他想法/改进...