【问题标题】:Graphviz straight linesGraphviz 直线
【发布时间】:2020-06-02 07:10:10
【问题描述】:

我试图获得从右侧退出节点并从左侧进入的直线边缘。 我尝试使用splines='line,但它似乎没有创建直线。下面的代码,在 jupyter notebook 中执行。

from graphviz import Digraph
g = Digraph('G', filename='cluster.gv')

with g.subgraph(name='cluster_0') as c:
    c.attr(style='filled', color='lightgrey')
    c.node_attr.update(style='filled', color='white')
    c.edges([('a0', 'a1'), ('a1', 'a2'), ('a2', 'a3')])
    c.attr(label='process #1')

with g.subgraph(name='cluster_1') as c:
    c.attr(color='blue')
    c.node_attr['style'] = 'filled'
    c.edges([('b0', 'b1'), ('b1', 'b2'), ('b2', 'b3')])
    c.attr(label='process #2')

g.edge('a1', 'b3',splines='line',tailport="e", headport="w", constraint='false')
g.edge('a2', 'b0',splines='line',tailport="e", headport="w", constraint='false')

g.view()

这是代码生成的图表: Graph

【问题讨论】:

    标签: graphviz spline subgraph


    【解决方案1】:

    我已经解决了这个问题。 splines='line' 的位置不正确。更正下面的代码,以防将来的用户遇到同样的问题。

    g = Digraph('G', filename='cluster.gv')
    
    with g.subgraph(name='cluster_0') as c:
        c.attr(style='filled', color='lightgrey')
        c.node_attr.update(style='filled', color='white')
        c.edges([('a0', 'a1'), ('a1', 'a2'), ('a2', 'a3')])
        c.attr(label='process #1')
    
    with g.subgraph(name='cluster_1') as c:
        c.attr(color='blue')
        c.node_attr['style'] = 'filled'
        c.edges([('b0', 'b1'), ('b1', 'b2'), ('b2', 'b3')])
        c.attr(label='process #2')
    
    g.attr(splines='false')
    g.edge('a1', 'b3',tailport="e", headport="w", constraint='false')
    g.edge('a2', 'b0',tailport="e", headport="w", constraint='false')
    
    g.view()
    

    【讨论】:

      猜你喜欢
      • 2013-10-18
      • 2014-08-02
      • 1970-01-01
      • 2011-06-07
      • 2021-08-22
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      相关资源
      最近更新 更多