Graphviz:如何使用circo布局排列节点

时间:2012-09-17 20:51:49

标签: graphviz

我正在尝试使用圆形拓扑绘制图形。

以下是我期待看到的内容: enter image description here

这是我的gv文件:

digraph g1 {
    layout="circo";
    node [shape = doublecircle]; N4 N6;
    node [shape = circle];
    N0 -> N1 [ label = "{1,0}"];
    N1 -> N2 [ label = "{1,0}"];
    N2 -> N3 [ label = "{1,0}"];
    N3 -> N4 [ label = "{1,0}"];
    N4 -> N5 [ label = "{1,0}"];
    N5 -> N6 [ label = "{1,0}"];
    N6 -> N0 [ label = "{1,0}"];

    N0 -> N4 [ label = "{1,0}"];
    N1 -> N5 [ label = "{1,0}"];
    N2 -> N6 [ label = "{1,0}"];
    N3 -> N0 [ label = "{1,0}"];
    N4 -> N1 [ label = "{1,0}"];
    N5 -> N2 [ label = "{1,0}"];
    N6 -> N3 [ label = "{1,0}"];    
}

这是上图的输出图像: enter image description here

如何在graphviz中安排节点使其看起来像1

1 个答案:

答案 0 :(得分:10)

如果目标是拥有一个尊重节点顺序的图形,那就不那么简单了。你可以calculate the position of the nodes with an external script and render it with neato

或者您可以首先使用边来布局节点,这些边仅确定节点的正确顺序:

digraph g1 {
    node [shape = doublecircle]; N4 N6;
    node [shape = circle];
    edge[label="{1,0}"];
    N0 -> N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N0;
}

使用:

circo graph.gv > tempgraph.gv

然后将剩余的边缘添加到tempgraph.gv - 只需在结束}之前复制粘贴以下内容:

N0 -> N4 [ label = "{1,0}"];
N1 -> N5 [ label = "{1,0}"];
N2 -> N6 [ label = "{1,0}"];
N3 -> N0 [ label = "{1,0}"];
N4 -> N1 [ label = "{1,0}"];
N5 -> N2 [ label = "{1,0}"];
N6 -> N3 [ label = "{1,0}"];

使用neato-n选项进行渲染:

neato -n tempgraph.gv -Tpng -O

您可能需要微调标签的位置:

circo layout