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"
+ colorlistソリューションを使用します。エッジにランダムに色を付けます。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"];
}
これにより、次が生成されます。

その他のアイデア/改善のお願い...