How to use lines with arrow in pydot

1.6k views Asked by At

I have drawn a binary search tree using pydot with these commands

graph = pydot.Dot(graph_type='graph')
visit(n5, BFS)
graph.write_png('example1_graph.png')

Where function view traverses the tree and calls a simple routine to draw the edges:

def draw(parent_name, child_name):
    # color for lines = red
    edge = pydot.Edge(parent_name, child_name, color="#ff0000")
    graph.add_edge(edge) 

But the lines connecting the nodes are simple straight lines. Is there a way to change the simple lines into directed arrows?

1

There are 1 answers

0
AudioBubble On BEST ANSWER

To connect nodes with arrows, use a directed graph type. Change the first line of the code, and the lines connecting nodes will be arrows instead of lines.

graph = pydot.Dot(graph_type='digraph')