Graphiz Edge变得疯狂

时间:2019-02-05 03:30:08

标签: graphviz dot

我想这样绘制马尔可夫链:enter image description here

因此,我尝试使用此代码:

digraph 
{
    center=true
    rankdir=TB;
    node [ shape = circle, width=0.3 ];

    S0:ne -> S1:nw [xlabel="9Z"]
    S1:ne -> S2:nw [xlabel="8Z"]
    S2:ne -> S3:nw [xlabel="7Z"]
    S3:ne -> S4:nw [xlabel="6Z"]
    S4:ne -> S5:nw [xlabel="5Z"]
    S5:ne -> S6:nw [xlabel="4Z"]
    S6:ne -> S7:nw [xlabel="3Z"]
    S7:ne -> S8:nw [xlabel="2Z"]
    S8:ne -> S9:nw [xlabel="1Z"]

    S1:sw -> S0:se [xlabel="M"]
    S2:sw -> S0:se [xlabel="M"]
    S3:sw -> S0:se [xlabel="M"]
    S4:sw -> S0:se [xlabel="M"]
    S5:sw -> S0:se [xlabel="M"]
    S6:sw -> S0:se [xlabel="M"]
    S7:sw -> S1:se [xlabel="M"]
    S8:sw -> S2:se [xlabel="M"]
    S9:sw -> S3:se [xlabel="M"]


    {rank = same; S0; S1; S2; S3; S4; S5; S6; S7; S8; S9;}
}

但这给了我那个结果: enter image description here

那是问题吗?为什么graphviz不想只扩大底部的图片?

P.S。我添加了graph [ranksep=5;]属性,它产生了以下内容:enter image description here。如何现在将此行放在底部?

1 个答案:

答案 0 :(得分:0)

不如第一张图片那么整洁,但是您可以尝试以下方法:

digraph
{   graph [ranksep=0.4 nodesep=0.1]
    node [ shape = circle, width=0.3];
    edge [arrowsize=0.7]
    rankdir=LR;

    S0:e -> S1:w [weight=2 style=invis]
    S1:e -> S2:w [weight=2 style=invis]
    S2:e -> S3:w [weight=2 style=invis]
    S3:e -> S4:w [weight=2 style=invis]
    S4:e -> S5:w [weight=2 style=invis]
    S5:e -> S6:w [weight=2 style=invis]
    S6:e -> S7:w [weight=2 style=invis]
    S7:e -> S8:w [weight=2 style=invis]
    S8:e -> S9:w [weight=2]

    S0:n -> S1:nw [xlabel="9Z"]
    S1:n -> S2:nw [xlabel="8Z"]
    S2:n -> S3:nw [xlabel="7Z"]
    S3:n -> S4:nw [xlabel="6Z"]
    S4:n -> S5:nw [xlabel="5Z"]
    S5:n -> S6:nw [xlabel="4Z"]
    S6:n -> S7:nw [xlabel="3Z"]
    S7:n -> S8:nw [xlabel="2Z"]
    S8:n -> S9:nw [xlabel="1Z"]

    S0:se -> S1:s [dir=back xlabel="M" constraint=false]
    S0:se -> S2:s [dir=back xlabel="M" constraint=false]
    S0:se -> S3:s [dir=back xlabel="M" constraint=false]
    S0:se -> S4:s [dir=back xlabel="M" constraint=false]
    S0:se -> S5:s [dir=back xlabel="M" constraint=false]
    S0:se -> S6:s [dir=back xlabel="M" constraint=false]
    S1:se -> S7:s [dir=back xlabel="M" constraint=false]
    S2:se -> S8:s [dir=back xlabel="M" constraint=false]
    S3:se -> S9:s [dir=back xlabel="M" constraint=false]

}

enter image description here