为了账号安全,请及时绑定邮箱和手机立即绑定

GRAPHVIZ:强制节点位于页面顶部

GRAPHVIZ:强制节点位于页面顶部

繁星点点滴滴 2023-10-31 14:06:52
我正在使用 graphviz,但是我想将节点“This on top”强制到页面顶部,而不是侧面。这是图表:这是代码:g= Digraph('trial', filename='trial.gv')g.attr(compound='true', rankdir="TB" )with g.subgraph() as s:  s.attr(rank='max')  s.node('This on top ')  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" )g是否有命令可以确保节点按我希望的顶部/底部顺序显示?
查看完整描述

1 回答

?
HUH函数

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

其产生:

https://img1.sycdn.imooc.com/654099ab000148b306530271.jpg

查看完整回答
反对 回复 2023-10-31
  • 1 回答
  • 0 关注
  • 58 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信