1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊
第一個(gè)問(wèn)題是,設(shè)置強(qiáng)制rank='max'第一個(gè)子圖中的所有內(nèi)容達(dá)到最高等級(jí),即最低等級(jí)。您可能打算設(shè)置rank='min'將子圖中的項(xiàng)目置于最高等級(jí),但這仍然無(wú)法創(chuàng)建您想要的排列。
相反,您可以通過(guò)在創(chuàng)建邊緣時(shí)進(jìn)行設(shè)置來(lái)使用不可見(jiàn)邊緣style = 'invis',以強(qiáng)制“此在頂部”位于“此在右下”之前。
from graphviz import Digraph
g= Digraph('trial', filename='trial.gv')
g.attr(compound='true', rankdir="TB" )
with g.subgraph() as s:
# s.attr(rank='min') # you don't need this line
s.node('This on top ')
s.edge('This on top ', 'this right under', style='invis') # add this invisible edge
s.edge('this right under', "Fabrication")
with g.subgraph(name='cluster0') as c:
c.node("This")
c.node("that")
c.node("and this on the same level")
g.edge("this right under", "that", lhead="cluster0" )
g.edge("that", "This on top ", ltail="cluster0", constraint="false" )
g
其產(chǎn)生:
添加回答
舉報(bào)