我是 graphviz 新手,只是想知道如何确定图中的相对节点位置。例如,如果我想绘制一个简单的三角形“abc”,节点“a”位于顶部,节点“b”和“c”位于底部同一水平,我应该如何告诉 graphviz 布局所需的节点?
我尝试了以下方法:
graph G
{
node [shape="circle"];
edge [lblstyle="auto"];
{rank=min; "a"}
a -- b [label = "-"];
a -- c [label = "-"];
{rank=same; "b" "c"}
b -- c [label = "+"];
}
但输出将节点“a”和“b”定位在顶部同一层,节点“c”位于底部。
此外,是否可以在同一个图中并排绘制两个这样的三角形(中间有适当的空间)?如果有,是如何实现的?
非常感谢。
最佳答案
but the output positions nodes 'a' and 'b' on the same level at the top, with node 'c' at the bottom.
我实际上得到了 a 在顶部,在 b 和 c 上方居中(见图)。
您的标记稍微简化了(lblstyle是什么?),在用点渲染时似乎达到了您想要的效果:
graph G
{
node[shape=circle];
a -- b [label = "-"];
a -- c [label = "-"];
{rank=same; b -- c [label="+"];}
}
您使用什么版本的 graphviz?
并且有两个并排的三角形:
graph G
{
node[shape=circle];
edge[label="-"];
a -- b;
a -- c;
{rank=same; b -- c [label="+"];}
d -- e;
d -- f;
{rank=same; e -- f [label="+"];}
}
但是,如果事情变得更加复杂,则可能很难让 graphviz 完全按照人们想要的方式布局所有内容。这实际上是 graphviz 的优势 - 应用布局算法以避免用户干预。
关于layout - 控制graphviz(dot2tex)中节点的布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6739163/