如何调整节点的外部标签

时间:2017-10-05 05:49:22

标签: graphviz dot

我想用一些外部标签绘制图形。

我发现有一些有用的属性 - xlabeltaillabelheadlabel但结果仍然看起来很奇怪。

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];
}

看起来像

enter image description here

正如您所看到的,标签和节点之间的一致性并不总是很明显。

所以,Q是 - 有没有办法改变标签的位置?

1 个答案:

答案 0 :(得分:1)

这可能不是你问题的答案,因为它仍然看起来不太好并且需要大量的手动调整,但我还是发布了它:我花了很长时间摆弄,可能有一些想法可能是对您的实际情况有所帮助:

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 }  
}

产量

enter image description here