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

Question:

I am trying to make a nice graph (see image), but has a certain requirement. Current graph The nodes that look like half rectangles called annotations should have the arrow enter into the node from the left and not from the bottom. Does anyone know how to do this in graphviz python.

Some remarks about the code:
The model object contains edge objects. Each edge object contains a source and a target node which are basically string objects.

I also kept a list of nodes that should have that half rectangle shape called annotations where I use that shape. The only thing I want in short is to get the incoming edge to move to the left.

The exact code can be found below:

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')`
Asked By: Alexandre Goossens

||

Answers:

Use "ports" (see p.18 "node ports" http://www.graphviz.org/pdf/dotguide.pdf and https://graphviz.org/docs/attr-types/portPos/)
So instead of a -> b try a -> b:w (:w indicating west or left side)

Answered By: sroush
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.