1 回答

TA貢獻1836條經驗 獲得超4個贊
第一個問題是,設置強制rank='max'第一個子圖中的所有內容達到最高等級,即最低等級。您可能打算設置rank='min'將子圖中的項目置于最高等級,但這仍然無法創建您想要的排列。
相反,您可以通過在創建邊緣時進行設置來使用不可見邊緣style = 'invis',以強制“此在頂部”位于“此在右下”之前。
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
其產生:
添加回答
舉報