Question

I wrote a python class to display and animate binary search trees. Yet the graphs produced by the pyDot edge and node commands don't seem to allow me to control the angle or direction of the arrows connecting each element of my tree.

There are lots of controls for shape of the nodes but there does not seem to be any control for angle of the lines. I was hoping to find some kind of minimum angle parameter to add to my edges as they are added to the graph?

This is a sample of my code where I draw nodes using the edge command:

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

The end result is that my graphs for binary search trees don't look like the traditional tree structures when several nodes have only one child.

Here is a link to my project where you can see the otherwise working results: http://www.embeddedcomponents.com/blogs/2013/12/visualizing-software-tree-structures/

Was it helpful?

Solution

from pydot documentation:

create will write the graph to a temporary dot file and process it with the program given by 'prog' (which defaults to 'twopi'), reading the Postscript output and returning it as a string is the operation is successful.

it is not possible to directly control edges angels using the dot language, but adding invisible edges can give you the result you want, see an example here that generates the following graph:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top