Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Graphviz

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use Graphviz". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use Graphviz.

Pre-preparation knowledge to install Graphviz

Step 1: install graphviz (downloadable .msi and installation-free version) on the Graphviz official website, and configure the bin directory to the environment variable Path after download.

Step 2: install graphviz on the command line, this module gives a lot of python interfaces to use Graphviz software

Pip install graphviz

What is python-graphviz?

Official website document

Graphviz is an open source graphics visualization software developed by AT&T Labs Research. Graphic visualization is a way to represent structural information as abstract graphics and network diagrams. It has important applications in the visual interface of network, bioinformatics, software engineering, database and web design, machine learning and other technical fields.

= = Features =: the Graphviz layout program takes a description of the graph in a simple text language and produces charts in useful formats, such as images for web pages and SVG;PDF or Postscript, for inclusion in other documents, or display in an interactive graphical browser. Graphviz has many useful features for specific charts, such as colors, fonts, table node layouts, line styles, hyperlinks and custom shape options.

Use principle: graphviz is actually a drawing tool, you can draw a tree diagram according to the dot script, = = We can use python code to generate a dot script, and then call graphviz to parse the script and generate a picture.

Dot scripting language: is a scripting language for drawing on the open source toolkit Graphviz. The syntax is very simple and the official document is only 8 pages long.

Case

Case 1:

From graphviz import Digraphdot = Digraph (comment='The Test Table') # annotate the dot scripting language #-create a node statement-# add a dot A tag is Dot Adot.node ('apocryphal,' Dot A') # add a dot B, B is labeled Dot Bdot.node ('Dot B') # add a dot C, and C is labeled Dot Cdot.node (name='C', label=' Dot C') Color='red') #-statement to create edges-(two ways) # create a pile of edges That is, two edges of AB are connected and one edge of AC is connected. Dot.edges (['AB',' AC']) # create an edge dot.edge ('baked,' clocked, 'test') between two dots created #-view the expression of the original dot language-# get the string form of the DOT source source code As shown in figure 1, print (dot.source) #-displays the image-# dot.view () directly, sets the picture name using the default name of dot.render ('test-table.gv', view=True) #, and displays directly

Dot script primitive:

Case 2:

From graphviz import Digraphsub_g0 = Digraph (comment= "process1", graph_attr= {"style": 'filled', "color":' lightgrey'}, node_attr= {"style": "filled", "color": "red"}) sub_g0.node ("a0", "a0") sub_g0.node ("A1", "A1") sub_g0.node ("a2", "a2") sub_g0.node ("a3", "a3") sub_g0.edge ("a0") "A1") sub_g0.edge ("A1", "a2") sub_g0.edge ("a2", "a3") sub_g0.edge ("a3", "a0") sub_g1 = Digraph (comment= "process1", graph_attr= {"style": 'filled'}) sub_g1.node ("B", "b0") sub_g1.node ("C", "b1") sub_g1.node ("D", "b2") sub_g1.node ("E") "b3") sub_g1.edges (["BC", "CD", "DE"]) grap_g = Digraph ("G", format= "pdf") grap_g.node ("start", label= "start", shape= "Mdiamond") grap_g.node ("end", label= "end", shape= "Mdiamond") grap_g.subgraph (sub_g0) # add Digraph from sub_g0 and sub_g0 to grap_g Digraph Convenient to display grap_g.subgraph (sub_g0) grap_g.edge ("start", "a0") grap_g.edge ("start", "B") grap_g.edge ("A1", "E") grap_g.edge ("D", "A3") grap_g.edge ("A3", "end") grap_g.edge ("E", "end") grap_g.view () # grap_g.render ('test-table2.gv', view=True) here I believe you have a deeper understanding of "how to use Graphviz". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report