Graphviz installation and introduction under windows

Finding good tools is like finding a new continent. Sometimes, we will be curious about how to make such image illustrations in papers and various professional books, without exception, the skillful use of drawing tools.

Download, install and configure environment variables


Download address of windows version:

Double click the msi file, and then continue to next (remember the installation path, the path information will be used to configure the environment variables later). After the installation is completed, the shortcut information will be created in the windows start menu. The default shortcut is not placed on the desktop.

Configure environment variables

Add the bin folder under the graphviz installation directory to the Path environment variable:


Enter the windows command line interface, enter dot version, and press enter. If the version information of graphviz is displayed, the installation configuration is successful.

Introduction to basic drawing

Open gvedit, the graphviz Editor under windows, write the following dot script language, and save it as gv format text file. Then enter the command line interface and use the dot command to convert the gv file into a png graphic file.

dot D:\test\1.gv -Tpng -o image.png


graph use -- describe relationships

graph pic1 { 
  a -- b
  a -- b
  b -- a [color=blue]


Use - > describe relationship

digraph pic2 { 
  a -> b
  a -> b
  b -> a [style=filled color=blue]

A complex example

digraph startgame {
    label="Game resource update process"
    start[label="start games" shape=circle style=filled]
    ifwifi[label="Network environment judgment WIFI" shape=diamond]
    needupdate[label="Whether there are resources to be updated" shape=diamond]
    startslientdl[label="Silent Download" shape=box]
    enterhall[label="Enter the game hall" shape=box]

    enterroom[label="get into the room" shape=box]
    resourceuptodate[label="Incomplete resources" shape=diamond]
    startplay[label="Normal game" shape=circle fillcolor=blue]
    warning[label="Remind players whether to update" shape=diamond]
    startdl[label="Enter the download interface" shape=box]
    //{rank=same; needupdate, enterhall}

    {shape=diamond; ifwifi, needupdate}

    start -> ifwifi

    enterhall -> enterroom
    enterroom -> resourceuptodate
    resourceuptodate -> warning[label="yes"]
    resourceuptodate -> startplay[label="no"]
    warning -> startdl[label="Confirm Download"]
    warning -> enterhall[label="Cancel Download"]
    startdl -> enterhall[label="Cancel Download"]
    startdl -> startplay[label="Download complete"]

Interact with python

graphviz's powerful and convenient method of drawing diagram / flow chart makes us easily associate with the way of displaying Decision Tree in machine learning. Fortunately, scikit learn provides an interface for generating. dot files. The specific operations are as follows:

In the python editing environment:

from sklearn.tree import export_graphviz    # Imported is a function
# tree represents the trained model, that is, the fit (x) of DecisionTreeClassifier instance has been called_ train, y_ Train) method
export_graphviz(tree, out_file='', 
        feature_names=['petal length', 'petal width'])

Enter the windows command line interface and switch cd to Path, executing

dot -Tpng -o tree.png

Tags: Windows Python PHP network

Posted on Tue, 16 Jun 2020 22:40:56 -0400 by kellydigital