首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图形化直线

图形化直线
EN

Stack Overflow用户
提问于 2020-02-18 17:45:23
回答 1查看 319关注 0票数 0

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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2020-02-18 18:42:23

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

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60277922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档