1

I want to construct a directed graph using python. How do I get the arcs to show arrowheads?

import graphviz and gv
import pylab

g1 = gv.Graph(format='png')

g1.node("A")
g1.node("B")

g1.edge("A", "B", arrowhead='normal')

g1.edge_attr.update(arrowhead="normal", arrowsize='2')
g1.graph_attr.update(directed="true")
g1.view()
print(g1.source) 

filename = g1.render(filename='img/g1')

pylab.savefig('filename.png')

What I get out is a graph but no arrow heads. I want the line between A and B to be an arrow pointing to B:

Graph but no arrowheads

The line

print(g1.source)

gives

graph {
graph [directed=true]
edge [arrowhead=normal arrowsize=2]
A
B
A -- B [arrowhead=normal]
}
Moni
  • 93
  • 1
  • 14

1 Answers1

0

I meet exactly the same problem in pygraphviz==1.6.

I am not sure if it behaves the same, but you can have a try

we have to define the graph as a directed graph before editing any of the edge attributes.

from pygraphviz import AGraph
A = AGraph(encoding="UTF-8",directed=True)

Instead of

A = AGraph(encoding="UTF-8")
Long
  • 366
  • 4
  • 13