Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在graphviz上显示树_Python 3.x_Binary Tree - Fatal编程技术网

Python 3.x 在graphviz上显示树

Python 3.x 在graphviz上显示树,python-3.x,binary-tree,Python 3.x,Binary Tree,我想知道如何在名为graphviz的软件上显示我的python代码。我想在graphviz上显示一个二叉树,就像这样 1 / \ 29 4 / \ 25 2 / 5 这是我为创建树而编写的代码,我只想知道如何使用点语言将其显示到graphviz中 def print_tree(tree): if tree is not None: print_tree(tree.get

我想知道如何在名为graphviz的软件上显示我的python代码。我想在graphviz上显示一个二叉树,就像这样

    1
   /  \
  29    4 
 /       \ 
25         2
         /
        5
这是我为创建树而编写的代码,我只想知道如何使用点语言将其显示到graphviz中

def print_tree(tree):
    if tree is not None:
            print_tree(tree.get_left_subtree())
            print(tree.get_value())
            print_tree(tree.get_right_subtree())

dot能够仅为边绘制图形。您可以打印所有的边(这将取决于您的树实现),并让点做其余的

编辑:点文件就是这样

Graph {
    a -- b -- c;
    d -- e;
}
因此,您可以使用python执行以下操作:

print("Graph {")
for e in g.edges():
    print(e[0], " -- ", e[1])
print("}")

问题是我不知道如何将python代码转换成点语言?点非常简单,它只是`图形{a--b;b--c;…}。使用python生成文件并用Graphviz.ahh编译好的,我明白了。问题是我将example.py文件保存为example.gv,以便在graphviz中打开它,但它给了我一个错误?为什么你的example.py会输出一些graphviz将使用的东西,所以更像是
python example.py>out.dot | graphviz out.dot-Tsvg
好的,谢谢!目前刚刚更改了代码,但出现错误,不确定是否正确,我将尝试解决:)