Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to annotate nodes and edges with Graphviz?

Tags:

graphviz

How can I draw a graph with Graphviz and annotate its nodes and edges?

For example:

(a: level=0) --3--> (b: level=1)  
(a: level=0) --2--> (c: level=1)
like image 734
Martin08 Avatar asked Jul 05 '12 01:07

Martin08


1 Answers

It is quite simple, here's a dot file for your example (test.dot):

strict digraph {
    1 [label="a: level=0"];
    2 [label="b: level=1"];
    3 [label="c: level=1"];
    1 -> 2 [label="3"];
    1 -> 3 [label="2"];
}

which with dot -Tpng -o test.png test.dot will output:

dot output

There are way more parameters you can set to get the layout that you want. I suggest you look through the Graphviz documentation.

like image 62
Maehler Avatar answered Sep 30 '22 12:09

Maehler