如何调整节点的外部标签
How to adjust outer labels for nodes
我想用一些外部标签绘制图表。
我发现有一些有用的属性 - xlabel
、taillabel
、headlabel
但结果看起来仍然很奇怪。
MCVE
digraph {
forcelabels=true;
node [shape=point,style=filled;label="",height=0.2];
y3[color=black;xlabel=<"y3 (2)">];x3[color=gray;xlabel=<"x3 [0.25]">];
y2[color=black;xlabel=<"y2 (3)">];x2[color=gray;xlabel=<"x2 [0.3]">];
y1[color=black;xlabel=<"y1 (2)">];x1[color=gray;xlabel=<"x1 [0.1]">];
y5[color=black;xlabel=<"y5 (4)">];x5[color=gray;xlabel=<"x5 [0.15]">];
x4[color=gray;xlabel=<"x4 [0.2]">];
y3->y2[dir=none;taillabel = 0.75];
y2->y1[dir=none;taillabel = 0.45];
y1->y5[dir=none;taillabel = 0.35];
y3->x3[dir=none];
y2->x2[dir=none];
y1->x1[dir=none];
y5->x5[dir=none];
y5->x4[dir=none];
}
看起来像
如您所见,标签和节点之间的一致性并不总是很明显。
所以,问题是 - 有什么方法可以更改标签的位置吗?
这可能不是你问题的答案,因为它看起来仍然不太好,需要大量手动调整,但我 post 无论如何:我花了很多时间摆弄,可能会有是一些可能对您的实际情况有帮助的想法:
digraph
{
forcelabels = TRUE;
splines = FALSE;
// nodes
node[ shape = point, style = filled, color = gray, label = "", height = 0.2 ];
x3[ xlabel = <"x3 [0.25]"> ];
x2[ xlabel = <"x2 [0.3]"> ];
x1[ xlabel = <"x1 [0.1]"> ];
x5[ xlabel = <"x5 [0.15]"> ];
x4;
node[ color = black ];
y3, y2, y1, y5;
node[ shape = plaintext, fillcolor = white ];
y_3[ label = "y3 (2)" ];
y_2[ label = "y2 (3)" ];
y_1[ label = "y1 (2)" ];
y_5[ label = "y5 (4)" ];
// edges
edge[ dir = none ];
y3:se -> y2[ label = " 0.75" ];
y2:se -> y1[ label = " 0.45" ];
y1:se -> y5[ label = " 0.35" ];
y3 -> x3;
y2 -> x2;
y1 -> x1;
y5 -> x5;
y5 -> x4[ headlabel = <"x4 [0.2]"> ];
edge[ style = invis ];
{ rank = same; y3 -> y_3 }
{ rank = same; y2 -> y_2 }
{ rank = same; y1 -> y_1 }
{ rank = same; y5 -> y_5 }
}
产量
我想用一些外部标签绘制图表。
我发现有一些有用的属性 - xlabel
、taillabel
、headlabel
但结果看起来仍然很奇怪。
MCVE
digraph {
forcelabels=true;
node [shape=point,style=filled;label="",height=0.2];
y3[color=black;xlabel=<"y3 (2)">];x3[color=gray;xlabel=<"x3 [0.25]">];
y2[color=black;xlabel=<"y2 (3)">];x2[color=gray;xlabel=<"x2 [0.3]">];
y1[color=black;xlabel=<"y1 (2)">];x1[color=gray;xlabel=<"x1 [0.1]">];
y5[color=black;xlabel=<"y5 (4)">];x5[color=gray;xlabel=<"x5 [0.15]">];
x4[color=gray;xlabel=<"x4 [0.2]">];
y3->y2[dir=none;taillabel = 0.75];
y2->y1[dir=none;taillabel = 0.45];
y1->y5[dir=none;taillabel = 0.35];
y3->x3[dir=none];
y2->x2[dir=none];
y1->x1[dir=none];
y5->x5[dir=none];
y5->x4[dir=none];
}
看起来像
如您所见,标签和节点之间的一致性并不总是很明显。
所以,问题是 - 有什么方法可以更改标签的位置吗?
这可能不是你问题的答案,因为它看起来仍然不太好,需要大量手动调整,但我 post 无论如何:我花了很多时间摆弄,可能会有是一些可能对您的实际情况有帮助的想法:
digraph
{
forcelabels = TRUE;
splines = FALSE;
// nodes
node[ shape = point, style = filled, color = gray, label = "", height = 0.2 ];
x3[ xlabel = <"x3 [0.25]"> ];
x2[ xlabel = <"x2 [0.3]"> ];
x1[ xlabel = <"x1 [0.1]"> ];
x5[ xlabel = <"x5 [0.15]"> ];
x4;
node[ color = black ];
y3, y2, y1, y5;
node[ shape = plaintext, fillcolor = white ];
y_3[ label = "y3 (2)" ];
y_2[ label = "y2 (3)" ];
y_1[ label = "y1 (2)" ];
y_5[ label = "y5 (4)" ];
// edges
edge[ dir = none ];
y3:se -> y2[ label = " 0.75" ];
y2:se -> y1[ label = " 0.45" ];
y1:se -> y5[ label = " 0.35" ];
y3 -> x3;
y2 -> x2;
y1 -> x1;
y5 -> x5;
y5 -> x4[ headlabel = <"x4 [0.2]"> ];
edge[ style = invis ];
{ rank = same; y3 -> y_3 }
{ rank = same; y2 -> y_2 }
{ rank = same; y1 -> y_1 }
{ rank = same; y5 -> y_5 }
}
产量