Drawing with graphviz

Source: Internet
Author: User
Tags fsm

Http://www.cnblogs.com/yushiro/archive/2008/06/23/1228371.html

Graphviz is a tool that converts a structure described in simple syntax into a graph. It is an open-source project developed by at&t research. You can see some samples on the official homepage.

Graphviz can be used on various platforms. First, download the version you need. After installation, the command is automatically added to the path.

Then edit a simple text file

 
Digraph G {
Begin-> end
}

Save it as a. Dot and run dot a. Dot-tpng-O a.png to generate the following figure.

The text files here are written according to the dot syntax. For details, refer to the document description.

There is no problem with Chinese support. You only need to specify the font. The available font list is those in Windows \ fonts. For example:

 
Digraph {
Node [fontname = "simhei. TTF"];
Edge [fontname = "simsun. TTC"];
"Nanjing"-> "Changle" [label = ""];
"Changle"-> "Fuzhou" [label = "Airport Bus"];
"Fuzhou"-> "Putian" [label = "Automobile"];
}
You can generate

Dot uses UTF-8 encoding by default, so you must save the file as UTF-8 encoding.

Dot is only one of the graphviz components used to generate directed graphs.

Graphviz's home page is http://www.graphviz.org/, which is a graph rendering tool developed by at&t labs-research. It can be easily used to draw a structured graph network and support output in multiple formats. The quality and speed of generating images are good.

Graphviz is an open-source product. You can download it here.And its demo Interface.

Graphviz supports many output formats.Check.

You can control the color of the image during the painting process.View.

Available resources include:

Customizable graph attributes

Customizable node shape

Customizable arrow shape

The last is related FAQs.You can find the answer to most questions here.

 

Http://blog.openrays.org/blog.php? Do = showone & tid = 420

 

Digitizes a directed graph, which can be expressed by an adjacent matrix.


After a computer processes the graph in a series (such as the closure), if you want to look at the processed graph, you can use graphviz, a powerful open-source tool.

1. graphviz Introduction

Graphviz is an automatic graph drawing tool developed by at&t labs-research. It can easily visualize structural information and present abstract graphs and networks in a geometric way. Supports output in multiple formats, such as JPG, PNG, GIF, SVG, Dia, and PS.

1.1 installation

Apt-Get install graphviz In Debian

Other platforms can go to its official website download: http://www.graphviz.org/Download..php

1.2 simple use

To generate a graph, you must first use the dot language defined by graphviz to describe your structured graph:

Digraph vis {
A-> B
C-> B
}

Save as HW. Dot

Execute dot-tsvg HW. Dot> HW. SVG to generate an SVG format image, as shown below:


Dot is generally used to draw Directed Graphs, while neato or FDP can be used to draw Directed Graphs. The difference is that the Directed Graphs generated by dot have better effects and those generated by neato and FDP have better effects. Other radiation-like images can be twopi or circular circles. Their command line parameters are consistent, but they are only usedAlgorithmNo.

For the following undirected graph:

Graph G {
Run -- intr;
Intr -- runbl;
Runbl -- run;
Run -- kernel;
Kernel -- Zombie;
Kernel -- sleep;
Kernel -- runmem;
Sleep -- swap;
Swap -- runswap;
Runswap -- new;
Runswap -- runmem;
New -- runmem;
Sleep -- runmem;
}

Neato-tsvg Proc. Dot-O Proc. SVG delivers better results, while FDP generates more compact images. Other generated graphs are relatively poor.

Neato generation:


FDP generation:


The production of a finite automatic machine is simply pediatrics:

digraph finite_state_machine {
rankdir = LR;
size = "8, 5"
node [shape = doublecircle]; lr_0 lr_3 lr_4 lr_8;
node [shape = circle];
lr_0-> lr_2 [label = "SS (B)"];
lr_0-> lr_1 [label = "SS (s)"];
lr_1-> lr_3 [label = "s ($ end)"];
lr_2-> lr_6 [label = "SS (B)"];
lr_2-> lr_5 [label = "SS (a)"];
lr_2-> lr_4 [label = "s (a)"];
lr_5-> lr_7 [label = "s (B)"];
lr_5-> lr_5 [label = "s (a)"];
lr_6-> lr_6 [label = "s (B)"];
lr_6-> lr_5 [label = "s (a)"];
lr_7-> lr_8 [label = "s (B)"];
lr_7-> lr_5 [label = "s (a)"];
lr_8-> lr_6 [label = "s (B)"];
lr_8-> lr_5 [label = "s (a)"];
}

Dot-tpng FSM. Dot-O fsm.png


For more information, see http://www.graphviz.org/gallery.php.

2. Visualize the adjacent matrix

Consider the following adjacent matrix:

# Define num 6

Int B [num] [num] =
{
0, 1, 0, 0, 1, 0,
0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 0
};

To visualize it, You can first convert it to the dot language description. Given the inherent advantages of the dot language description structure, you can easily write down the following c Function Conversion:

Void gen_graphic (const char * fname)
{
File * FP;
Int K, J;
Char name [255];
Char cmd [255];

Sprintf (name, "% S. Dot", fname );
Fp = fopen (name, "WB ");

Fputs ("digraph vis {\ n", FP );
Fputs ("\ tsize = \" 5, 3 \ "; \ t/* Set IMG width * Height in inch */\ n", FP );

For (k = 0; k <num; k ++)
For (j = 0; j <num; j ++)
If (B [k] [J])
Fprintf (FP, "\ t % d-> % d; \ n", k + 1, J + 1 );

Fputs ("} \ n", FP );
Fclose (FP );

Sprintf (CMD, "Circo-tsvg % S. Dot> % S. SVG", fname, fname );
System (CMD );
}

After several attempts, we found that this graph is better able to use Circo, even though the officially recommended Directed Graph Generation Tool is dot.

Call this function gen_graphic (vis_src); the resulting adjacent matrix is:


The graph after closure operation is:


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.