2015-04-25 61 views
0

我想用graphviz繪製決策樹圖。強制graphviz中的節點從左到右的順序?

我想提請看起來像這樣的圖表:

enter image description here

我使用下面的dot語言:

graph a { 
    A [shape=box; label="A"] 
    B [shape=box; label="B"] 
    al [shape=none; label="0"] 
    bl [shape=none; label="1"] 
    br [shape=none; label="0"] 

    A -- al [label="0"]; 
    A -- B [label="1"]; 
    B -- bl [label="0"]; 
    B -- br [label="1"]; 

} 

但是我得到的圖形看起來是這樣的:

enter image description here

如何強制graphviz生成的節點的從左到右的順序?而且,就決策樹而言,即使從左到右排序不同,這兩棵樹也完全一樣嗎?

+0

你在用什麼語言? –

+0

@TimBiegeleisen你好,我只是手寫了.gv文件。 – georgelappies

回答

2

爲了解決這個問題,你可以改變Bal節點的順序:

graph a { 
    A [shape=box; label="A"] 
    al [shape=none; label="0"] 
    B [shape=box; label="B"] 
    bl [shape=none; label="1"] 
    br [shape=none; label="0"] 

    A -- al [label="0"]; 
    A -- B [label="1"]; 
    B -- bl [label="0"]; 
    B -- br [label="1"]; 
} 

順便說一句,在graphviz的網站有一個blog post about this problem,你可以看看,如果你得到一個機會。

+1

謝謝,這工作。非常感激。 – georgelappies