Is there a way to control line angle when producing graphs with pyDot

走远了吗. 提交于 2019-12-24 13:17:16

问题


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/


回答1:


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:



来源:https://stackoverflow.com/questions/20533753/is-there-a-way-to-control-line-angle-when-producing-graphs-with-pydot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!