如何在节点graphviz中设置头部和尾部位置

How to set head and tail position in nodes graphviz

我无法控制 2 个节点之间边的头尾位置。

我正在设置一个如下图所示的节点

digraph G{
  node [shape = "box"]
  a -> b
  b -> a
}

可以使用 罗盘点 定义边的头部和尾部位置,如 The dot language, or by using the headport or tailport 属性中指定:

digraph G{
  node [shape = "box"]
  a:w -> b:w
  b -> a [headport=e, tailport=e]
}

第一部分与@marapet 已经给出的答案基本相同:

digraph G
{
   node[ shape = "box" ];
   a:w -> b:w;
   a:e -> b:e[ dir = back ];
}

它生成一个圆边图:

如果没问题,那么应该采纳marapet的回答。

如果您坚持使用您在 post 中提供的形状,则需要应用更复杂的程序:

digraph G
{
    // we create the two nodes to be displayed
    node[ shape = "box" ];
    a b;
    //we also create four empty nodes for routing the edges
    node[ shape = point, height = 0 ];
    x1 x2 x3 x4;
    // we make sure that the nodes are arranged on the right levels
    { rank = same; x1 a x2 }
    { rank = same; x3 b x4 }

    // we draw the edges one by one as the heads are varying
    x1 -> a[ dir = none ];
    a -> x2[ dir = back ];
    x1 -> x3[ dir = none ];
    x2 -> x4[ dir = none ];
    b -> x4[ dir = none ];
    x3 -> b;
}

这给了你