使graphviz树的父母居于孩子之上 [英] Making graphviz trees have parents centred above children
问题描述
我有以下graphviz代码:
I have the following graphviz code:
graph {
node[width = 0.6, height = 0.6, fixedsize=true, shape=circle];
a[label="22"];
b[label="22"];
c[label="34"];
d[label="22"];
e[label="99"];
f[label="34"];
g[label="40"];
h[label="37"];
i[label="22"];
j[label="99"];
k[label="135"];
l[label="129"];
m[label="40"];
edge[penwidth=3.0];
a -- b;
b -- d;
c -- f;
d -- i;
e -- j;
g -- m;
edge[penwidth=1.0];
a -- c;
b -- e;
c -- g;
d -- h;
e -- k;
g -- l;
}
这是为了绘制突出显示某些边缘的二叉树。但是,树看起来不太正确-特别是在树的更下方,父母和孩子的排列如下:
This is meant to draw a binary tree with some edges highlighted. However, the tree doesn't look quite right - especially further-down the tree, the arrangement of parent and children looks like this:
parent
child child
而我希望它看起来像这样:
whereas I would like it to look more like this:
parent
child child
(即,使父母居中于孩子上方,而不是坐在其中一个的上方)。这可能吗?如果可以,我该怎么办?
(i.e. have the parent centred above its children, not sitting on top of one of them). Is this possible, and how would I do it if so?
推荐答案
按照此链接的答案使用 gvpr 和Emden R. Gansner的脚本很好地布局了二叉树,我得到以下输出:
Following the instructions in this linked answer using gvpr and Emden R. Gansner's script to nicely layout binary trees, I get the following output:
想不出更好或更快速的方式。
Can't think of a better or faster way.
这篇关于使graphviz树的父母居于孩子之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!