Graphviz study notes

  What I want to say is that Graphviz is my gospel... Recently I have been looking for how to use code to realize data structure visualization, flowcharts, etc., so I found her, and it is relatively easy to get started, but just as I Only when I thought it was good, I found that I could even write it in python, and I was instantly full of favorability! so excited~

  Let's briefly talk about how to use it under Windows:

  First of all, whether you write digraph directly or use python, you must install and configure it. Configuration is actually a common practice. Just add the file paths such as dot.exe to the system environment variable PATH. Then you can use notepad to write code, save it as .gv or .dot suffix, and then use the dot command to compile it into pdf, png, jpg, etc. For example, write the following:

digraph tree {
	node [shape=circle]
	67
	53
	79
	46
	57
	70
	88
	43
	55
	60
	74
	56
	67 -> 53
	67 -> 79
	53 -> 46
	53 -> 57
	79 -> 70
	79 -> 88
	46 -> 43
	57 -> 55
	57 -> 60
	55 -> 56
	70 -> 74
}

  Then type the dot command:

  If there is no error, you can open tree.png:

  Writing graphviz in python also requires using pip to install a package:

$ pip install graphviz

  Then refer to this document to learn.

  one example:

from graphviz import Digraph, Graph

dot = Digraph(name='tree', node_attr={'shape': 'circle'})

dot.node('67')
dot.node('53')
dot.node('79')
dot.node('46')
dot.node('57')
dot.node('70')
dot.node('88')
dot.node('43')
dot.node('55')
dot.node('60')
dot.node('74')
dot.node('56')

dot.edge('67', '53')
dot.edge('67', '79')
dot.edge('53', '46')
dot.edge('53', '57')
dot.edge('79', '70')
dot.edge('79', '88')
dot.edge('46', '43')
dot.edge('57', '55')
dot.edge('57', '60')
dot.edge('55', '56')
dot.edge('70', '74')
print(dot.source)
dot.render('avl-tree.gv', view=True)

  Here I don't know why I have configured the path, but at the end of the operation, it will still report the error that the corresponding file path cannot be found, but I can still generate the 'avl-tree.gv' file, and then I have to manually compile the file on the command line. .

  screenshot:

  Still output the .gv file:

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325343458&siteId=291194637