Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz outputs a mess

Tags:

graphviz

I'm trying to visualise the following data in dot format using GraphViz:

digraph n {   node [nodesep=2.0, fontsize=11];   graph [ overlap=false];   edge[weight=0.2];   A -> B [label="I/5"]   A -> A [label="*/0"]   A -> C [label="ii/2"]   A -> H [label="vii/1"]   B -> D [label="iii/1"]   B -> E [label="IV/2"]   B -> F [label="V/2"]   B -> B [label="vi/2"]   C -> F [label="V/2"]   C -> H [label="vii/1"]   D -> E [label="IV/2"]   E -> D [label="iii/2"]   E -> G [label="iv/1"]   E -> F [label="V/3"]   F -> B [label="I/4"]   F -> B [label="vi/1"]   F -> B [label="*/0"]   G -> B [label="I/5"]   H -> B [label="vi/1"] } 

Running the following command: neato -Tpng Chord_NFA.dot > Chord_NFA.png

gives me this output:

I'd like it to fit on A4 and for none of the edges to overlap or cross over a node. This is possible (mathematically) because I did it myself with a biro.

like image 630
Ivy Avatar asked May 03 '12 20:05

Ivy


People also ask

How do I use DOT in Graphviz?

How do I use graphviz to convert this into an image? For windows: dl the msi and install; Find gvedit.exe in your programs list; Open . dot file in question; Click running person on toolbar; Go to graph -> settings ; change Output file type to file type of your liking and press ok..

How do you order nodes in Graphviz?

If ordering="out" , then the outedges of a node, that is, edges with the node as its tail node, must appear left-to-right in the same order in which they are defined in the input. If ordering="in" , then the inedges of a node must appear left-to-right in the same order in which they are defined in the input.

What is rank in Graphviz?

Ranks and Subgraphs To work out the layout, Graphviz uses a system it calls "ranks". Each node is assigned a higher rank than the highest ranked node that point to it. If your rank direction is set to left to right ( rankdir=LR ), then nodes with a higher rank are placed further to the right.

What language does Graphviz use?

Graphviz consists of a graph description language named the DOT language and a set of tools that can generate and/or process DOT files: dot. a command-line tool to produce layered drawings of directed graphs in a variety of output formats, such as (PostScript, PDF, SVG, annotated text and so on). neato.


1 Answers

Here's a some steps in a better direction:

  • nodesep is not a node-attribute - and it probably doesn't do what you expected. But it still is useful in your case:

    ... this affects the spacing between loops on a single node, or multiedges between a pair of nodes.

  • I don't think edge weight changes something if you change it for all edges.
  • Enabling splines is often a good idea.
  • Adding additional space around the nodes can be done with sep
  • overlap has more values than true/false - I often find scalexy useful.
  • Once the node distribution is ok, you may fine-tune label positions by using a combination of headlabel/taillabel, labeldistance and labelangle (red in the example below to make them stand out).

Here's the modified sample:

digraph n { splines=true; sep="+25,25"; overlap=scalexy; nodesep=0.6; node [fontsize=11]; //edge[weight=0.2];  A -> B [label="I/5"] A -> A [label="*/0"] A -> C [label="ii/2"] A -> H [label="vii/1"] B -> D [label="iii/1"] B -> E [label="IV/2"] B -> F [headlabel="V/2", labeldistance=4, labelangle=-10, labelfontcolor=red] B -> B [label="vi/2"] C -> F [label="V/2"] C -> H [label="vii/1"] D -> E [label="IV/2"] E -> D [label="iii/2"] E -> G [label="iv/1"] E -> F [headlabel="V/3", labeldistance=8, labelangle=-7, labelfontcolor=red] F -> B [label="I/4"] F -> B [label="vi/1"] F -> B [label="*/0"] G -> B [taillabel="I/5", labeldistance=4, labelangle=15, labelfontcolor=red] H -> B [label="vi/1"] } 

graphviz output

like image 101
marapet Avatar answered Oct 04 '22 16:10

marapet