使用graphviz将节点定位到子图的右侧

问题描述 投票:1回答:1

我正在使用graphviz绘制一个简单的潜变量模型的DAG:

digraph G {

    splines=line;

    subgraph cluster {
        node [style=filled, shape=circle];
        edge [color=blue]
        z[fillcolor=white, color=black, pos = "0,0!"]
        z -> x;
    }

    theta[label = "θ", shape=circle, pos = "10,0!"]
    edge [color=black, style="dashed"]
    theta->z
    theta->x

}

输出很不错:

enter image description here

但我希望θ与z处于同一高度。那可能吗?我试图使用pos属性,但正如你所看到的,它被很好地忽略了。我在HackMD工作。

position graphviz directed-acyclic-graphs
1个回答
1
投票

您可以将constraint=false属性添加到theta边缘,这样它们就不会影响布局,节点将保持并排:

digraph G {

    splines=line;

    subgraph cluster1 {
        node [style=filled, shape=circle];
        edge [color=blue]
        z[fillcolor=white, color=black, pos = "0,0!"]
        z -> x;
    }
    theta[label = "θ", shape=circle, pos = "10,0!"]
    edge [color=black, style="dashed"]
    theta -> z [constraint=false]
    theta -> x [constraint=false] // actually this one is unnecessary, may be omited in this example

}

此外,您可以尝试边缘方向(例如,更改位置a-> b,b-> a),这有时有助于定位群集。

© www.soinside.com 2019 - 2024. All rights reserved.