graphviz and tikz

78
The installation How it works Conclusions Graphviz and Tik Z Claudio Fiandrino December 4, 2011 Claudio Fiandrino Graphviz and TikZ December 4, 2011 1 of 51

Post on 13-Sep-2014

1.737 views

Category:

Self Improvement


1 download

DESCRIPTION

How to export a graph realized through Graphviz into a TikZ picture for a LaTeX document.

TRANSCRIPT

Page 1: Graphviz and TikZ

The installation How it works Conclusions

Graphviz and TikZ

Claudio Fiandrino

December 4, 2011

Claudio Fiandrino Graphviz and TikZ December 4, 2011 1 of 51

Page 2: Graphviz and TikZ

The installation How it works Conclusions

Index

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 2 of 51

Page 3: Graphviz and TikZ

The installation How it works Conclusions

Introduction

Graphviz is a tool that allows to build graphsIn this presentation we analyse how is it possible export aGraphviz result in a TikZ picture thanks to:

dot2tex

The operating system used is Ubuntu 11.04Each example contains:

the dot codethe graphical result obtained by running pdfLATEX

Examples are mainly derived from the web site of dot2tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 3 of 51

Page 4: Graphviz and TikZ

The installation How it works Conclusions

Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 4 of 51

Page 5: Graphviz and TikZ

The installation How it works Conclusions

Requirements for dot2tex

As reported in the dot2tex main page, the following software arerequired:

python, version 2.4 of laterpyparsing version 1.4.8 (recommended) or laterGraphvizPreview LATEX package

to not have problems I suggest to install TEXLive: this helps ifyou want to exploit the dot2texi package and, of course, withTikZ/PGF

TikZ/PGFin case you have TEXLive you do not need to install anymore

Claudio Fiandrino Graphviz and TikZ December 4, 2011 5 of 51

Page 6: Graphviz and TikZ

The installation How it works Conclusions

Installation of pyparsing

An easy way to install things is to use easy_install.

Easy_InstallOpen your terminal and do:

sudo apt -get install python -setuptools

PyparsingDigit, again in the terminal:

sudo easy_install pyparsing

Claudio Fiandrino Graphviz and TikZ December 4, 2011 6 of 51

Page 7: Graphviz and TikZ

The installation How it works Conclusions

Installation of pyparsing

An easy way to install things is to use easy_install.

Easy_InstallOpen your terminal and do:

sudo apt -get install python -setuptools

PyparsingDigit, again in the terminal:

sudo easy_install pyparsing

Claudio Fiandrino Graphviz and TikZ December 4, 2011 6 of 51

Page 8: Graphviz and TikZ

The installation How it works Conclusions

Installation of Graphviz

Open Synaptic, the packet manager, and install the followings:graphviz, graphviz-doc, graphviz-dev, libgraphviz-dev,libgraphviz-perllibgv-lua, libgv-perl, libgv-php5, libgv-guile, libgv-python,libgv-ruby, libgv-tlc, libgv-ocaml

Claudio Fiandrino Graphviz and TikZ December 4, 2011 7 of 51

Page 9: Graphviz and TikZ

The installation How it works Conclusions

Installation of dot2tex

There are two ways to install it:by means of easy_installby downloading it

from the source pagefrom CTAN

Through easy_installWith the terminal, do:

sudo easy_install dot2tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 8 of 51

Page 10: Graphviz and TikZ

The installation How it works Conclusions

Installation of dot2tex

There are two ways to install it:by means of easy_installby downloading it

from the source pagefrom CTAN

From sourceAfter having downloaded the .zip file, unpack it, move into thedirectory and do:

sudo python setup.py install

Claudio Fiandrino Graphviz and TikZ December 4, 2011 9 of 51

Page 11: Graphviz and TikZ

The installation How it works Conclusions

Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 10 of 51

Page 12: Graphviz and TikZ

The installation How it works Conclusions

How it works - Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 11 of 51

Page 13: Graphviz and TikZ

The installation How it works Conclusions

The dot code

Create in your desktop a directory named ex1Create with gedit a new empty file called ex1.dot and pastethis code:

digraph G {1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];

}

Claudio Fiandrino Graphviz and TikZ December 4, 2011 12 of 51

Page 14: Graphviz and TikZ

The installation How it works Conclusions

Obtaining the TikZ picture

At this point use the terminal to move into the folder:

cd Desktop/ex1/

To create the .tex file use:

dot2tex --preproc ex1.dot | dot2tex > ex1.tex

To obtain the image, run:

pdflatex ex1.tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 13 of 51

Page 15: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 16: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 17: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 18: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 19: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 20: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 21: Graphviz and TikZ

The installation How it works Conclusions

The result

The LATEX document created by runningthe dot2tex command is complete

it has its own preambleit uses one page just for the picturethe result is shown on the right

Pay attention: the option preproc needsPreviewYou can copy the code of the picture intoanother document, but be aware of insertalso the tikzlibrary reported in thepreamble

\usepackage{tikz}\usetikzl ibrary {snakes ,arrows ,shapes}

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 14 of 51

Page 22: Graphviz and TikZ

The installation How it works Conclusions

How it works - Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 15 of 51

Page 23: Graphviz and TikZ

The installation How it works Conclusions

The output options

If you do not specify nothing, the picture is written in PGFcode; the same result is obtained thanks to the option fpgfTo have the picture in TikZ code the option that has to beexploited is ftikzThe last option is fpst: this force the software to writePSTricks code

Example PGF

dot2tex -fpgf ex1.dot > ex1_pgf.tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 16 of 51

Page 24: Graphviz and TikZ

The installation How it works Conclusions

The output options

If you do not specify nothing, the picture is written in PGFcode; the same result is obtained thanks to the option fpgfTo have the picture in TikZ code the option that has to beexploited is ftikzThe last option is fpst: this force the software to writePSTricks code

Example TikZ

dot2tex -ftikz ex1.dot > ex1_tikz.tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 17 of 51

Page 25: Graphviz and TikZ

The installation How it works Conclusions

The output options

If you do not specify nothing, the picture is written in PGFcode; the same result is obtained thanks to the option fpgfTo have the picture in TikZ code the option that has to beexploited is ftikzThe last option is fpst: this force the software to writePSTricks code

Example PSTricks

dot2tex -fpst ex1.dot > ex1_pst.tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 18 of 51

Page 26: Graphviz and TikZ

The installation How it works Conclusions

What are the differences?

PSTricks, to the best knowledge of the author, today is notlargely used as TikZ/PGFPGF is much more machine-friendly

more lines of code are necessary than TikZTikZ is user-friendly

the suggestion is to use it if you want successively modify thepicture

Claudio Fiandrino Graphviz and TikZ December 4, 2011 19 of 51

Page 27: Graphviz and TikZ

The installation How it works Conclusions

How it works - Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 20 of 51

Page 28: Graphviz and TikZ

The installation How it works Conclusions

The dot code

In this second example, we introduce labels also into nodes.Create in your desktop a directory named ex2Create with gedit a new empty file called ex2.dot and pastethis code:

digraph G {a_1 ->b_2 [ label ="1/2"];b_2 ->c_3 [ label ="1/2"];c_3 ->a_1 [ label ="1/2"];

}

Claudio Fiandrino Graphviz and TikZ December 4, 2011 21 of 51

Page 29: Graphviz and TikZ

The installation How it works Conclusions

Obtaining the TikZ picture

In this frame are reported three ways to obtain the picture:in math mode, the label will be put into $ $: useful torepresent the usual math relations of LATEX

dot2tex -tmath ex2.dot > ex2.tex

in verbatim mode, the label will not show special LATEXcharacters

dot2tex -tverbatim ex2.dot > ex2.tex

in raw mode, the label will not be processed at all

dot2tex -traw ex2.dot > ex2.tex

Claudio Fiandrino Graphviz and TikZ December 4, 2011 22 of 51

Page 30: Graphviz and TikZ

The installation How it works Conclusions

The results

Math mode:

1/2

1/2

1/2

b2

c3

a1

Verbatim mode:

1/2

1/2

1/2

b_2

c_3

a_1

Raw mode:

by running pdflatexyou obtain an error:this is due to thefact that in LATEXthe _ character isa special characterand, to be repre-sented needs \_

Claudio Fiandrino Graphviz and TikZ December 4, 2011 23 of 51

Page 31: Graphviz and TikZ

The installation How it works Conclusions

Another method to put labels

It is possible introduce labelsfor nodes also into the dotcode:

digraph G {1 [ texlbl ="$a_1$ "];2 [ texlbl ="$b_2$ "];3 [ texlbl ="$c_3$ "];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];

}

In this case, you just need:

dot2tex ex2.dot > ex2.tex

The mode can be omittedbecause is assumed to be giveninside the texlbl.

Claudio Fiandrino Graphviz and TikZ December 4, 2011 24 of 51

Page 32: Graphviz and TikZ

The installation How it works Conclusions

How it works - Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 25 of 51

Page 33: Graphviz and TikZ

The installation How it works Conclusions

Label colors

To insert a colored label, use:

digraph G {1 [ texlbl ="$a_1$", lb l s ty le ="red "];2 [ texlbl ="$b_2$ "];3 [ texlbl ="$c_3$ "];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 26 of 51

Page 34: Graphviz and TikZ

The installation How it works Conclusions

Label colors

To insert a colored label, use:

digraph G {1 [ texlbl ="$a_1$", lb l s ty le ="red "];2 [ texlbl ="$b_2$ "];3 [ texlbl ="$c_3$ "];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 26 of 51

Page 35: Graphviz and TikZ

The installation How it works Conclusions

Label colors

To insert a colored label, use:

digraph G {1 [ texlbl ="$a_1$", lb l s ty le ="red "];2 [ texlbl ="$b_2$ "];3 [ texlbl ="$c_3$ "];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 26 of 51

Page 36: Graphviz and TikZ

The installation How it works Conclusions

Label colors

To insert a colored label, use:

digraph G {1 [ texlbl ="$a_1$", lb l s ty le ="red "];2 [ texlbl ="$b_2$ "];3 [ texlbl ="$c_3$ "];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 26 of 51

Page 37: Graphviz and TikZ

The installation How it works Conclusions

Other options

In general, into the lblstyle it is possibleto introduce standard statements of Tikz:

digraph G {1 [ texlbl ="$a_1$", lb lsty le ="red"];2 [ texlbl ="$b_2$", lb lsty le ="red"];3 [ texlbl ="$c_3$", lb lsty le ="red"];1->2 [ label ="1/2" ,

lb lsty le =" rounded corners ,fill=blue!20, rotate =30"];

2->3 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue !20"];

3->1 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue!20, below =0.1cm"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 27 of 51

Page 38: Graphviz and TikZ

The installation How it works Conclusions

Other options

In general, into the lblstyle it is possibleto introduce standard statements of Tikz:

digraph G {1 [ texlbl ="$a_1$", lb lsty le ="red"];2 [ texlbl ="$b_2$", lb lsty le ="red"];3 [ texlbl ="$c_3$", lb lsty le ="red"];1->2 [ label ="1/2" ,

lb lsty le =" rounded corners ,fill=blue!20, rotate =30"];

2->3 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue !20"];

3->1 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue!20, below =0.1cm"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 27 of 51

Page 39: Graphviz and TikZ

The installation How it works Conclusions

Other options

In general, into the lblstyle it is possibleto introduce standard statements of Tikz:

digraph G {1 [ texlbl ="$a_1$", lb lsty le ="red"];2 [ texlbl ="$b_2$", lb lsty le ="red"];3 [ texlbl ="$c_3$", lb lsty le ="red"];1->2 [ label ="1/2" ,

lb lsty le =" rounded corners ,fill=blue!20, rotate =30"];

2->3 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue !20"];

3->1 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue!20, below =0.1cm"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 27 of 51

Page 40: Graphviz and TikZ

The installation How it works Conclusions

Other options

In general, into the lblstyle it is possibleto introduce standard statements of Tikz:

digraph G {1 [ texlbl ="$a_1$", lb lsty le ="red"];2 [ texlbl ="$b_2$", lb lsty le ="red"];3 [ texlbl ="$c_3$", lb lsty le ="red"];1->2 [ label ="1/2" ,

lb lsty le =" rounded corners ,fill=blue!20, rotate =30"];

2->3 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue !20"];

3->1 [ label ="1/2" ,lb lsty le =" rounded corners ,fill=blue!20, below =0.1cm"];

}

The result is:

1/2

1/2

1/2

a1

c3

b2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 27 of 51

Page 41: Graphviz and TikZ

The installation How it works Conclusions

How it works - Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 28 of 51

Page 42: Graphviz and TikZ

The installation How it works Conclusions

Node characterization

Nodes may have different:shapes

ellipsecirclerectangle

coloursborder colorfill color

fontsThere are two ways to characterize nodes:

global definition (useful to characterize the majority of nodes)single definition

Claudio Fiandrino Graphviz and TikZ December 4, 2011 29 of 51

Page 43: Graphviz and TikZ

The installation How it works Conclusions

An example

Through the keyword style, nodes arecustomized with the usual statements ofTikz:

digraph G {node [ style ="fill=green !20"];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];3 [shape=rectangle ,

style ="fill=cyan!20,draw=blue"]}

By using:

dot2tex -ftikz ex3.dot > ex3.tex

the result is:

1

3

2 1/2

1/2

1/2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 30 of 51

Page 44: Graphviz and TikZ

The installation How it works Conclusions

An example

Through the keyword style, nodes arecustomized with the usual statements ofTikz:

digraph G {node [ style ="fill=green !20"];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];3 [shape=rectangle ,

style ="fill=cyan!20,draw=blue"]}

By using:

dot2tex -ftikz ex3.dot > ex3.tex

the result is:

1

3

2 1/2

1/2

1/2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 30 of 51

Page 45: Graphviz and TikZ

The installation How it works Conclusions

An example

Through the keyword style, nodes arecustomized with the usual statements ofTikz:

digraph G {node [ style ="fill=green !20"];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];3 [shape=rectangle ,

style ="fill=cyan!20,draw=blue"]}

By using:

dot2tex -ftikz ex3.dot > ex3.tex

the result is:

1

3

2 1/2

1/2

1/2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 30 of 51

Page 46: Graphviz and TikZ

The installation How it works Conclusions

An example

The same code:

digraph G {node [ style ="fill=green !20"];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];3 [shape=rectangle ,

style ="fill=cyan!20,draw=blue"]}

By using the default processing (pgf):

dot2tex ex3.dot > ex3_pgf.tex

gives this result:

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 31 of 51

Page 47: Graphviz and TikZ

The installation How it works Conclusions

An example

The same code:

digraph G {node [ style ="fill=green !20"];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];3 [shape=rectangle ,

style ="fill=cyan!20,draw=blue"]}

By using the default processing (pgf):

dot2tex ex3.dot > ex3_pgf.tex

gives this result:

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 31 of 51

Page 48: Graphviz and TikZ

The installation How it works Conclusions

An example

The same code:

digraph G {node [ style ="fill=green !20"];1->2 [ label ="1/2"];2->3 [ label ="1/2"];3->1 [ label ="1/2"];3 [shape=rectangle ,

style ="fill=cyan!20,draw=blue"]}

By using the default processing (pgf):

dot2tex ex3.dot > ex3_pgf.tex

gives this result:

1/2

1/2

1/2

1

3

2

Claudio Fiandrino Graphviz and TikZ December 4, 2011 31 of 51

Page 49: Graphviz and TikZ

The installation How it works Conclusions

Defining types

In TikZ, it is possible to define types for nodesuse the d2tfigpreamble at the beginning of the dot file

In the online documentation is not reported the case of pluraldefinition

for the best knowledge of the author this feature isfundamentalthe next example highlight this fact

Claudio Fiandrino Graphviz and TikZ December 4, 2011 32 of 51

Page 50: Graphviz and TikZ

The installation How it works Conclusions

Example with types

This graph will have two types of nodes coloured differently

digraph G {d2tfigpreamble = "\ tikzstyle{statecold }= \[draw=blue!50,very thick ,fill=blue !20],\tikzstyle{statehot }= \[draw=red!50,very thick ,fill=red !20]";A [ style =" statecold "];B [ style =" statecold "];C [ style =" statehot "];D [ style =" statehot "];A->B->D;A->C->D;D->C;D->B->A;B->B [topath="loop left "];C->B;

}

Claudio Fiandrino Graphviz and TikZ December 4, 2011 33 of 51

Page 51: Graphviz and TikZ

The installation How it works Conclusions

Example with types

Please note the syntax:inside " " the entire definition is reported (both two states inthis case)you have to put a \ both in front of tikzstyle and before thedefinition of the type (into [ ]): this is fundamental!you have to separate types with a ,

The option topaths will be subsequently treated

Claudio Fiandrino Graphviz and TikZ December 4, 2011 34 of 51

Page 52: Graphviz and TikZ

The installation How it works Conclusions

The result (I)

By using:

circo -Txdot ex4.dot | dot2tex -ftikz > ex4.texpdflatex ex4.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 35 of 51

Page 53: Graphviz and TikZ

The installation How it works Conclusions

The result (I)

By using:

circo -Txdot ex4.dot | dot2tex -ftikz > ex4.texpdflatex ex4.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 35 of 51

Page 54: Graphviz and TikZ

The installation How it works Conclusions

The result (I)

By using:

circo -Txdot ex4.dot | dot2tex -ftikz > ex4.texpdflatex ex4.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 35 of 51

Page 55: Graphviz and TikZ

The installation How it works Conclusions

The result (II)

By using:

circo -Txdot ex4.dot |dot2tex -ftikz --styleonly > ex4.tex

pdflatex ex4.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 36 of 51

Page 56: Graphviz and TikZ

The installation How it works Conclusions

The result (II)

By using:

circo -Txdot ex4.dot |dot2tex -ftikz --styleonly > ex4.tex

pdflatex ex4.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 36 of 51

Page 57: Graphviz and TikZ

The installation How it works Conclusions

The result (II)

By using:

circo -Txdot ex4.dot |dot2tex -ftikz --styleonly > ex4.tex

pdflatex ex4.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 36 of 51

Page 58: Graphviz and TikZ

The installation How it works Conclusions

The result (III)

By using:

neato -Txdot ex4.dot |dot2tex -ftikz --styleonly > ex4.tex

pdflatex ex4.tex

we obtain:

AC

B

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 37 of 51

Page 59: Graphviz and TikZ

The installation How it works Conclusions

The result (III)

By using:

neato -Txdot ex4.dot |dot2tex -ftikz --styleonly > ex4.tex

pdflatex ex4.tex

we obtain:

AC

B

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 37 of 51

Page 60: Graphviz and TikZ

The installation How it works Conclusions

The result (III)

By using:

neato -Txdot ex4.dot |dot2tex -ftikz --styleonly > ex4.tex

pdflatex ex4.tex

we obtain:

AC

B

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 37 of 51

Page 61: Graphviz and TikZ

The installation How it works Conclusions

Results motivations

By processing the dot file through circo or neato allows toobtain different kind of results

the difference is the layout output

circo is preferable with regular topologies

Claudio Fiandrino Graphviz and TikZ December 4, 2011 38 of 51

Page 62: Graphviz and TikZ

The installation How it works Conclusions

How it works - Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 39 of 51

Page 63: Graphviz and TikZ

The installation How it works Conclusions

Edge characterization

Also edges can be characterized:though the dot syntax:

edge [ style ="..."];

by means of the option topath:

a -> b [topath="..."];

with this options, the usual statements of TikZ can be used

Claudio Fiandrino Graphviz and TikZ December 4, 2011 40 of 51

Page 64: Graphviz and TikZ

The installation How it works Conclusions

An example: the code

In this example we exploit the first option:

digraph G {d2tfigpreamble = "\ tikzstyle{statecold }= \[draw=blue!50,very thick ,fill=blue !20],\tikzstyle{statehot }= \[draw=red!50,very thick ,fill=red !20]";A [ style =" statecold "];B [ style =" statecold "];C [ style =" statehot "];D [ style =" statehot "];edge [ style ="snake=zigzag "];A->B->D->C->A;edge [ style ="snake=snake "];A->D;C->B;

}

Claudio Fiandrino Graphviz and TikZ December 4, 2011 41 of 51

Page 65: Graphviz and TikZ

The installation How it works Conclusions

An example: the result

By using:

circo -Txdot ex5.dot | dot2tex -ftikz -s > ex5.texpdflatex ex5.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 42 of 51

Page 66: Graphviz and TikZ

The installation How it works Conclusions

An example: the result

By using:

circo -Txdot ex5.dot | dot2tex -ftikz -s > ex5.texpdflatex ex5.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 42 of 51

Page 67: Graphviz and TikZ

The installation How it works Conclusions

An example: the result

By using:

circo -Txdot ex5.dot | dot2tex -ftikz -s > ex5.texpdflatex ex5.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 42 of 51

Page 68: Graphviz and TikZ

The installation How it works Conclusions

Considerations

The -s option is needed to manage snakesThe tikzlibrary snakes is now deprecated: although thepackage requires it, should be better exploit the librarydecorations

would be interesting because decorations allows to exploitpre/post length options and other shapes

It is possible of course change later the library, but you areforced also to insert manually the new options in the TikZ code

Claudio Fiandrino Graphviz and TikZ December 4, 2011 43 of 51

Page 69: Graphviz and TikZ

The installation How it works Conclusions

Another example: the code

In this example we exploit the topath option:

digraph G {d2tfigpreamble = "\ tikzstyle{statecold }= \[draw=blue!50,very thick ,fill=blue !20],\tikzstyle{statehot }= \[draw=red!50,very thick ,fill=red !20]";A [ style =" statecold "];B [ style =" statecold "];C [ style =" statehot "];D [ style =" statehot "];A->B->D->C->A[topath="bend left =20"];A->C->D->B->A[topath="bend left =20"];B->B [topath="loop left "];

}

Claudio Fiandrino Graphviz and TikZ December 4, 2011 44 of 51

Page 70: Graphviz and TikZ

The installation How it works Conclusions

An example: the result

By using:

circo -Txdot ex6.dot | dot2tex -ftikz > ex6.texpdflatex ex6.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 45 of 51

Page 71: Graphviz and TikZ

The installation How it works Conclusions

An example: the result

By using:

circo -Txdot ex6.dot | dot2tex -ftikz > ex6.texpdflatex ex6.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 45 of 51

Page 72: Graphviz and TikZ

The installation How it works Conclusions

An example: the result

By using:

circo -Txdot ex6.dot | dot2tex -ftikz > ex6.texpdflatex ex6.tex

we obtain:

A

CB

D

Claudio Fiandrino Graphviz and TikZ December 4, 2011 45 of 51

Page 73: Graphviz and TikZ

The installation How it works Conclusions

Outline

1 The installation

2 How it worksThe first exampleThe outputThe second exampleLabel propertyNode propertyEdge property

3 Conclusions

Claudio Fiandrino Graphviz and TikZ December 4, 2011 46 of 51

Page 74: Graphviz and TikZ

The installation How it works Conclusions

Why use dot?

Someone can claim: why use dot and not directly TikZ?The dot language is much more intuitivelyYou can achieve more or less the same quality of TikZIt is more suitable for very large graphs

Claudio Fiandrino Graphviz and TikZ December 4, 2011 47 of 51

Page 75: Graphviz and TikZ

The installation How it works Conclusions

Where is convenient to use TikZ?

I think that if you just have to insert a small graph in a documentand it has to be created from scratch, the best way to do it is usedirectly TikZ. For example:

0 123

12

1/2

1/3

which has been created thanks to the code reported in thefollowing slide.

Claudio Fiandrino Graphviz and TikZ December 4, 2011 48 of 51

Page 76: Graphviz and TikZ

The installation How it works Conclusions

Code of previous example

\begin{lstlisting}\begin{tikzpicture}[-latex ,auto ,node distance =4cm ,on grid ,semithick ,state /. style ={circle ,top color=white ,bottom color=processblue !20,draw , processblue ,circular drop shadow ,text=blue ,minimum width =1cm}]\node[state] (A) {$0$};\node[state] (B) [ right=of A] {$1$};\path (A) edge [loop left] node{$\dfrac {2}{3}$} (A);\path (B) edge [loop right] node{$\dfrac {1}{2}$} (B);\path (B) edge [bend left =25] node[below]{$1/2$} (A);\path (A) edge [bend right =-25 ] node[above]{$1/3$} (B);\end{tikzpicture}

Claudio Fiandrino Graphviz and TikZ December 4, 2011 49 of 51

Page 77: Graphviz and TikZ

The installation How it works Conclusions

Comments

The main concept is the definition of the state: this is similarto the procedure used through the option d2tfigpreambleThe nodes must be placed in some sense (the position of B isgiven in terms of A’s position): in dot this step is completelyavoidedThe syntax to connect nodes is a bit more heavy than dot

Claudio Fiandrino Graphviz and TikZ December 4, 2011 50 of 51

Page 78: Graphviz and TikZ

The installation How it works Conclusions

Licence and Credit

This presentation:is licensed (CC BY-NC-ND 3.0)has been realized through Arkyenell Theme licensed(CC BY-NC-SA 3.0)

Claudio Fiandrino Graphviz and TikZ December 4, 2011 51 of 51