【问题标题】:Graphviz: Loop to the left should have the same shape as loop to the rightGraphviz:左侧的循环应该与右侧的循环具有相同的形状
【发布时间】:2018-09-26 16:29:40
【问题描述】:

考虑这个小图:

digraph G {
    {rank = same; node12; node11;}

    node11 [ label = "node left", shape=square ]
    node11 -> node11 [label=" i[2,9]"]
    node11 -> node12 [label=" k[2]"]
    node12 [ label = "node right", shape=square ]
    node12 -> node12 [label=" i[9]"]
}

我使用dot -Tpdf将其转换为pdf

$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)

如您所见,左节点的(自)循环与连接左右节点的边重叠。我试图通过使用graphviz 的compass 功能来解决这个问题。我的第一次尝试是:node11:w -> node11:w [label=" i[2,9]"]:

但是,循环的最终形状发生了变化。我不想要这个,我同意它看起来 uglier。增加nodesep=1; 不会给您与正确的形状相同的形状。当然,您可以通过添加:e 使右循环与左循环相同。但我更喜欢原始右环的形状。

还有其他可能实现这一点吗?

顺便说一句:Mathematica 绘图在这里更聪明:它会自动将自循环放置到另一侧。但恕我直言,需要大量定制才能获得中性风格:

Graph[{1 -> 1, 1 -> 2, 2 -> 2}, 
 EdgeLabels -> {(1 -> 1) -> "i[2,9]", (1 -> 2) -> "k[2]", (2 -> 2) -> 
    "i[9]"}, EdgeLabelStyle -> Directive[15, Background -> White], 
 VertexSize -> 0.3, VertexShapeFunction -> "Rectangle", 
 VertexStyle -> White, EdgeStyle -> Black, 
 VertexLabels -> {1 -> Placed["node left", Center], 
   2 -> Placed["node right", Center]}]

并且要明确一点:这只是图表的一部分。最终的图表如下所示:

【问题讨论】:

    标签: graphviz


    【解决方案1】:

    你也许可以这样做:

    digraph G {
    
      node[margin=0 _color=invis shape=none height=.2
      label=<<table BORDER="1" CELLBORDER="0" CELLPADDING="0" CELLSPACING="0">
        <tr>
            <td port="a1"></td>
            <td port="b1"></td>
            <td port="c1"></td>
            <td port="d1"></td>
            <td port="e1"></td>
        </tr>
        <tr>
            <td port="a2"></td>
            <td rowspan="3" colspan="3">
            \N
            </td>
            <td port="e2"></td>
        </tr>
        <tr>
            <td port="a3"></td>
            <td port="e3"></td>
        </tr>
        <tr>
            <td port="a4"></td>
            <td port="e4"></td>
        </tr>
        <tr>
            <td port="a5"></td>
            <td port="b5"></td>
            <td port="c5"></td>
            <td port="d5"></td>
            <td port="e5"></td>
        </tr>
      </table>>]
    
      x:a2:w->x:a4:w
      x:e2:e->x:e4:e
      x->y
      y:a2:w->y:a4:w
    }
    

    由 viz-js.com 渲染:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多