使graphviz树的父母居于孩子之上 [英] Making graphviz trees have parents centred above children

查看:77
本文介绍了使graphviz树的父母居于孩子之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆