繁体   English   中英

在 graphviz python 中强制箭头从左侧进入节点

[英]Force an arrow to enter a node from the left in graphviz python

我正在尝试制作一个漂亮的图表(见图),但有一定的要求。 当前图 看起来像半矩形的节点称为注释,箭头应该从左侧而不是底部进入节点。 有谁知道如何在 graphviz python 中执行此操作。

关于代码的一些评论: model object 包含边缘对象。 每条边 object 包含一个源节点和一个目标节点,它们基本上是字符串对象。

我还保留了一个节点列表,这些节点应该具有我使用该形状的称为注释的半矩形形状。 总之,我唯一想要的就是让传入的边缘向左移动。

确切的代码可以在下面找到:

g = Digraph('G', filename='./output/model_' + str(mi),     format='png',strict=True)
g.graph_attr.update(rankdir='BT')
g.attr('node',shape='note')
sources= list()
targets = list()
annotations=list()
PossibleModel.MAX_DEPTH = 3

"""Let us first see what the possible inputs are"""
"""  
for edge in model.get_edges():
    sources.append(str(edge.source))
    targets.append(str(edge.target))
"""  
for edge in model.get_edges():
    sources.append(edge.source.small_string2())
    targets.append(edge.target.small_string2())
  
difference = list(set(sources) - set(targets))
print('difference',difference)



for edge in model.get_edges():
    edge_contained = ''
    for rule in br_rules:
        if str(edge.source) in rule or str(edge.target) in rule:
            edge_contained += rule + '\n'
    if edge_contained == '':
        g.edge(edge.source.small_string2(), edge.target.small_string2(),label=str(edge.weight),color='red')
        g.edge(edge.source.small_string2(), edge.source.small_string3(),color='black',arrowhead='none',style='dashed')
        g.edge(edge.target.small_string2(), edge.target.small_string3(),color='black',arrowhead='none',style='dashed')
        annotations.append(edge.source.small_string3())
        annotations.append(edge.target.small_string3())
    else:
        g.attr('edge', color='blue')
        g.edge(str(edge.source), str(edge.target), label=edge_contained)

for node in difference:
    g.node(node,style='rounded',shape='ellipse')

for node in targets:
    g.node(node, shape='box')
    
for node in annotations:
    g.node(node,color='transparent', image='test.png',fontsize='11')`

使用“端口”(参见第 18 页“节点端口” http://www.graphviz.org/pdf/dotguide.pdfhttps://graphviz.org/docs/attr-types/portPos/
所以而不是a -> b试试a -> b:w:w表示西边左边

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM