In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Python graphviz drawing example analysis, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Foreword:
Recently, I was about to start to set up a class, and the topic was Huffman coding. I was wondering if there was any way to print the structure of a tree (in fact, I was asked to print a tree in an experiment, which was not realized at that time). When I came across a blog article that mentioned graphviz, I glanced at it and was shocked to find that I could print various shapes and flow charts.
So immediately pip install graphviz, the library downloaded quickly, but in any case can not draw a picture, tossing about for nearly an hour, it was found in a boss's blog that it is necessary to add graphviz to the environment variable.
In short, although there is a problem, the state of mind is very broken, but, to solve the problem at that moment, really happy!
1.graphviz installation and configuration
Enter the official website to download: https://graphviz.org/download/
(the version basically does not affect the use, any one is fine.)
After downloading, there will be an installation process, all next can be, remember to check to join PATH!
If it is not checked, remember to manually add it to the path of the environment variable, or you will become unlucky, like me.
Also, after adding environment variables, you have to restart the compiler, otherwise it's useless.
After joining, it goes like this:
2.dot and graphviz
Dot
Dot is a text graphics description language, written .dot files can be processed into pictures, usually can generate .png, .jpg, .pdf and other formats.
Graphviz
Graphviz is an open source library of python, and various operations of dot are included in graphviz.
Graphviz can be used to draw simple flowcharts.
In my opinion, it is super convenient to draw trees and graphs of data structures.
Drawing:
Step1: importing graphviz library
From graphviz import Digraph # Import graphviz Library
Step: create a table
Dot = Digraph (name, comment)
Add point
Dot.node (name, label)
Create edges between point
Dot.edge (tail_name, head_name, label)
Output the drawing
Dot.view ()
Generate picture file
Print (dot.source) render (filename=None, directory=None, view=False, cleanup=False) # parameters are file name, file save path, whether to open the rendering effect with the default program, and whether to delete the source file after rendering
Sample
From graphviz import Digraph # Import graphviz library dot = Digraph ("lmy's table", comment='The Test Table') # create a table dot.node ('Aids,' Dot A') # add a point The name of the point is' Dot A'dot.node ('baked,' Dot B') dot.node ('Dot,' Dot C') dot.node ('Dot,' Dot D') dot.edges (['AD',' AC', 'BC']) # create an edge between two points dot.edge (' baked, 'clocked,' test') # dot.view () This function can see the figure you drew in real time # get the string form of DOT source source code print (dot.source) # / The Test Table# digraph {# A [label= "Dot A"] # B [label= "Dot B"] # C [label= "Dot C"] # A-> B# A-> C # A-> B# B-> C [label=test] #} # Save source to the file And provide Graphviz engine dot.render ('test-output/lmy.gv', view=True)
Running result:
You can see that a pdf file is generated
After reading the above, have you mastered the method of example analysis of python graphviz drawing? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.