python drawing graphviz

dot drawing
python drawing graphviz

environment

It was installed locally in the previous section graphviz. If you want to use python, you need to install the pip package.

pip install graphviz

python use

dot = Digraph(comment="My Graph")
# 添加一些节点
dot.node("A", "Node A")
dot.node("B", "Node B")
dot.node("C", "Node C")
dot.node("D", "Node D")
# 添加一些边
dot.edge("A", "B")
dot.edge("A", "C")
dot.edge("C", "D")
# 保存图像
dot.render("my_graph", view=True)

renderings

Insert image description here

Common mistakes

 No module named 'graphviz'

Just installing the python package is not enough, you also need to install graphvizthe software.

Guess you like

Origin blog.csdn.net/tyustli/article/details/133356217