# Graphviz FAQ 2004-12-15

Stephen North, Emden Gansner, John Ellson

Note: This is not a tutorial; to understand the following, you should know how to use the basic features of the tools and languages involved. Please see the user guides and documentation for further information or the resources page for a partial list of compatible tools and packages.

## General

Q. Where can I see a list of all the attributes that control dot or neato?

See Graph Attributes. There is also information on command-line usage and output formats.

Q. Where can I discuss Graphviz?

We run a mailing list.

To subscribe or unsubscribe, visit the graphviz-interest mailman control page. See also the general instructions for mailman.

You can also see the archive.

You may wish to use a Yahoo or Hotmail account if you're concerned about spam. We also run anti-spam filters, and rewrite `@` as `at` to keep verbatim addresses out of the archive.

Please, please, please, do not torment the mailing list with beginner's questions or software build problems. First, check this FAQ and the message archive carefully. Because Graphviz software is made available without charge, our resources for routine support are very limited. If you are desperate, please contact ellson, erg, or north@research.att.com.

Also, if a program crashes or you get an abort or something strange occurs and you are fairly comfortable using the tools: <BL>

- Check the open bug list to see if a similar bug has already been reported. You might also consider checking the full bug list, since your bug may have been reported and fixed in the working version.
- Submit a bug report. If you prefer, you can download a report in text form, fill in the fields, and email it to gviz-bugs@research.att.com. </BL>

  Q. I'm trying to make a layout larger. How?

  There are various ways to increase the size of a layout. In doing this, one has to decide if the sizes of the nodes and text should be increased as well.

  One approach is to adjust individual parameters such as `fontsize, nodesep` and `ranksep`. For example,

                 digraph G {
                      graph [fontsize=24];
                      edge  [fontsize=24];
                      node  [fontsize=24];
                      ranksep = 1.5;
                      nodesep = .25;
                      edge [style="setlinewidth(3)"];
                      a -> b -> c;
                 }

  If you do this, make sure you are not fighting a conflicting graph size setting, like `size="6,6"`, which will then scale everything back down.

  If you are using fdp or neato, increasing the edge len will tend to expand the layout.

              graph G {
                 edge [len=3]
                 a -- { b c d }
              }

  For twopi and circo, there are other parameters such as `ranksep` which can be used. See the graph attributes.

  You can also use the `ratio` attribute. If you set the `size` attribute to the desired drawing size, and then set `ratio=fill`, node positions are scaled separately in x and y until the drawing fills the specified `size`. Note that node sizes stay the same. If, instead, you set `ratio=expand`, the layout is uniformly scaled up in x and y until at least one dimension fits `size`.

  If you specify the `size` attribute but end it with an exclamation mark (!), the final drawing will be scaled up uniformly in x and y until at least one dimension fits `size`. Note that everything is scaled up, including text and node sizes.

  If you're using Postscript, you can just scale up the output by manually adding a command such as `2 2 scale` where the Postscript environment is set up. Make sure to adjust the `BoundingBox` too if your tools look at this header.

  Q. How can I join or merge certain edge routes in dot?

  You can try running `dot -Gconcentrate=true` or you can introduce your own virtual nodes drawn as tiny circles where you want to split or join edges:

      digraph G {
        yourvirtualnode [shape=circle,width=.01,height=.01,label=""];
        a -> yourvirtualnode [arrowhead=none]
        yourvirtualnode -> {b;c}
      }

  Q. How can I generate graph layouts in PDF?

  First, create Postscript output, then use an external converter from Postscript to PDF. For example,
  `dot -Tps | epsf2pdf -o file.pdf`
  Note that URL tags are respected, to allow clickable PDF objects.

  If your intention is to use the figure as PDF in some document preparation system, such as pdflatex, it is very important to use -Tps2 rather than -Tps. In general, if you really want PDF output, that is, you would like to have a -Tpdf flag, use -Tps2 before converting to PDF.

  Q. How can I make duplicate nodes?

  Make unique nodes with duplicate labels.

            digraph G {
                  node001 [label = "A"];
                  node002 [label = "A"];
      			node001 -> node002;
      	  }

  Q. How can I set a graph or cluster label without its propagating to all sub-clusters?

  Set the label at the end of the graph (before the closing brace), after all its contents have been defined. (We admit it seems desirable to define some special syntax for non-inherited attribute settings.)

  Q. How can I draw multiple parallel edges in neato?

  This is possible when the `splines` attribute is false, which is the default. When `splines=true`, we have no good answer but we are working on it. One trick which is sometimes sufficient is to specify multiple colors for the edge. This will a produce set of tightly parallel splines, each in its specified color. Read about the color attribute for more information.

  ## Clusters

  Q. How can I create edges between cluster boxes?

  This only works in Graphviz version 1.7 and higher. To make edges between clusters, first set the graph attribute `compound=true`. Then, you can specify a cluster by name as a logical head or tail to an edge. This will cause the edge joining the two nodes to be clipped to the exterior of the box around the given cluster.

  For example,

            digraph G {
              compound=true;
              nodesep=1.0;
              subgraph cluster_A {
                a -> b;
                a -> c;
              }
              subgraph cluster_B {
                d -> e;
                f -> e;
              }
              a -> e [ ltail=cluster_A,
                       lhead=cluster_B ];
            }

  has an edge going from `cluster_A` to `cluster_B`. If, instead, you say

              a -> e [ltail=cluster_A];

  this gives you an edge from `cluster_A` to node `e`. Or you could just specify an `lhead` attribute. The program warns if a cluster specified as a logical node is not defined. Also, if a cluster is specified as a logical head for an edge, the real head must be contained in the cluster, and the real tail must not be. A similar check is done for logical tails. In these cases, the edge is drawn between the real nodes as usual.

  Q. Clusters are hard to see.

  Set bgcolor=grey (or some other color) in the cluster.

  Q. How can I symmetrize (balance) tree layouts?

  When a tree node has an even number of children, it isn't necessarily centered above the two middle ones. If you know the order of the children, a simple hack is to introduce new, invisible middle nodes to re-balance the layout. The connecting edges should also be invisible. For example:

      digraph G {
      a -> b0;
      xb [label="",width=.1,style=invis]
      a -> xb [style=invis];
      a -> b1;
      {rank=same b0 ->  xb -> b1 [style=invis]}
      b0 -> c0;
      xc [label="",width=.1,style=invis]
      b0 -> xc [style=invis];
      b0 -> c1;
      {rank=same c0 ->  xc -> c1 [style=invis]}
      }

  This trick really ought to be build into our solver (and made independent of the order of the children, and available for layouts other than trees, too).

  ## Output features

  Q. I can only get 11x17 output.

  It's not us! It's probably your printer setup. If you don't believe this, run `dot -Tps` and look at the `BoundingBox` header. The coords are in 1/72ths of an inch.

  Q. How do I create special symbols and accents in labels?

  The following solution only works with the raster drivers that load Truetype or Type1 fonts! (That means, `-Tgif, -Tpng, -Tjpeg`, and possibly `-Tbmp` or `-Txbm` if enabled). Use UTF8 coding, e.g. <verb>¥</verb> for the Yen currency symbol. Example: graph G { yen [label="¥"] }

  You can look up other examples in this handy character set reference .

  Q. How do I get font and color changes in record labels or other labels?

  This is not possible in record shapes. However, you can do this using HTML-like labels. The granularity of changes is still at the cell level, but by playing with cell spacing and padding, you can get pretty much the effect you want. The intention is to support arbitrary font changes within running text in the not-too-distant future.

  Q. In plain format, splines do not touch the nodes (arrowheads are missing).

  Edges are specified as the main spline and, if necessary, arrowheads which actually abut the node. If the arrowheads are not given, drawing the edge spline will leave a gap between the edge and the node. This is a bug which has now solidified into a feature. A workaround is to set

            edge [dir=none]

  Since the edges have no arrowheads, the spline specification will go all the way to both nodes.

  Q. Record nodes are drawn differently in dot and neato when rankdir=LR.

  It's true. dot -Grankdir=LR rotates record nodes so that their top level fields are still listed across levels. rankdir=LR has no effect in neato. One workaround is HTML-like records (they don't rotate; the downside is that you have to write in XML). Another workaround is to enclose record labels in { } to rotate/unrotate the record contents. See also, How To Avoid Foolish Consistency by Scott Berkun (Microsoft Corp.)

  Q. How can I print a big graph on multiple pages?

  The `page` attribute, if set, tells Graphviz to print the graph as an array of pages of the given size. Thus, the graph

      digraph G {
        page="8.5,11";
        ...
      }

  will be emitted as 8.5 by 11 inch pages. When printed, the pages can be tiled to make a drawing of the entire graph. At present, the feature only works with PostScript output.

  Alternatively, there are various tools and viewers which will take a large picture and allow you to extract page-size pieces, which can then be printed.

  Q. When I have a red edge it shows up as a solid red in PNG and GIF formats, but has a black border when rendered to JPEG.

  This is an artifact of JPEG's lossy compression algorithm. JPEG isn't very good for line drawings. PNG is bitmap format of choice. John Ellson wants to deprecate and eventually remove the JPEG driver, but North is reluctant to change anything that people might already rely on.

  Q. How can I get custom shapes or images in my graph?

  Please see the Shape HowTo for some approaches. There is no easy way to create custom shapes that work with dot/neato, dotty (Unix or MS-Windows) and Grappa (the Java front end), because they don't share any universal back end structure. We're thinking about it.

  Q. Sometimes in dotty, right mouse click shows the global menu but none of the items can be selected.

  Check that the NUMLOCK key is off. It's a known bug.

  Q. How can I get some display feature (such as bold lines) in dotty?

  Dotty has not really changed for many years. Therefore, there are myriad features available in Graphviz which it cannot handle. In some cases, you can use Grappa or webdot for display instead of dotty. For example, Grappa has generalized polygons (`node [shape=polygon]`) that dotty lacks. There are additional interactive viewers available. For example, see Graphical Interfaces and Viewers. If you are using MacOSX, the Mac version of Graphviz has a highly recommended GUI.

  If the display attribute that you need isn't there already, in dotty, there's probably no easy way to do it except by rolling up your sleeves and hacking the dotty code (a lefty script) that interprets and renders graphical attributes. This is problematic for the same reason as above: there's no universal low-level driver layer shared across all the Graphviz tools. We recently added an intermediate rendering language to the layout tools, but the various front ends don't use it yet. This would be a good project for someone who wants to get involved here (along with porting dotty to GTK.)

  Q. How can I get rid of the little circles on edges ("edge handles") in dotty?

  Edit the file dotty.lefty and change the line that says: 'edgehandles' = 1; to 'edgehandles' = 0; it's around line 110.

  Q. I already have all the coordinates for the nodes and edges of my graph and just want to use dot, neato, or dotty to render it. How?

  Put the graph with layout attributes into a dot file. Then run `neato -s -n2`. For example:

      neato -s -n2 -Tgif file.dot -o file.gif

  Note that if an edge does not have a `pos` attribute defined, neato will perform whatever edge routing it would normally do. All of the usual backend attributes (`size`, `overlap`, `page`, etc.) are available.

  Q. I already have all the coordinates for the nodes, and I want dot or neato to route the edges.

  It's not really too convenient to use dot for this. It is possible to use neato for this, running neato -s -n For example:

      neato -s -n -Tgif file.dot -o file.gif

  neato will use the node positions, but use its technique for routing the edges. There are several things to note. First, the neato edge router is different from dot's. Without the built-in top-down bias, it doesn't do as good a job of avoiding edge overlaps and, at present, it doesn't handle spline multi-edges at all. Second, by default, neato uses straight lines as edges. To get spline routing, you have to specify -Gsplines=true. And this will only work if none of the nodes overlap. Since the input graph supplies fixed node positions, it is the user's task to insure this.

  Q. I already have all the coordinates for the nodes and edges of my graph and just want to use dotty to render it. How?

  Just run dotty on it. Dotty will use the given pos attributes.

  Q. Same as above, but I have only node coords, not edges.

  `neato -n -s` is some help, but neato doesn't handle spline-based parallel edges.

  Q. How can I make client-side image maps?

  Use the -Tcmap command line option (only version 1.8.9 and beyond!)

  Q. Why aren't my server-side maps being recognized? I've checked the HTML!

  Make sure that your server has map files enabled. For example, if running apache, check that httpd.conf has a line like the following:

      AddHandler imap-file map

  and that it is not commented out!

  Q. I've installed Debian Graphviz and it works just fine on the command line, but when I execute a Perl/CGI script through Apache, no output is generated. For example, the code

      system("/usr/local/bin/dot -Tpng /tmp/tree.dot -o /tmp/tree.png");

  produces no file `/tmp/tree.png`.

  As best as we can tell, dot dies with no stdout or stderr messages on Debian systems when run from an Apache cgi program with no HOME set. The workaround is to provide a HOME directory in the Apache userid's environment.

  Someone has also suggested using the Perl module for Graphviz.

  Q. How can I get 3D output?

  The Graphviz authors have qualms about the gratuitous use of 3D.

  Nonetheless, dot -Tvrml generates VRML files. There's no Z coordinate layout - you specify Z coords yourself in the `z` attribute of nodes, and the Z coordinates of edges are interpolated. If someone contributes a driver for a newer, more useful format (OpenGL Performer scene graphs? Open Scene Graphs? Java3D programs?) we'd like to try it.

  neato internally supports layouts in higher dimensions through the `dim` attribute, e.g. `neato -Gdim=7` but there's no way to get the output unless you invoke neato as a library and inspect <verb>ND_pos(n)[i]</verb> where <verb>n</verb> is a pointer to the relevant node. This would need some (minor) driver work and a good 7-dimensional viewer. Well, `dim=3` ought to be possible.

  ## Problems

  Q. How can I avoid node overlaps in neato?

  Use the graph attribute `overlap`.

  Q. How can I avoid node-edge overlaps in neato?

  Use the `overlap` attribute to leave room among the nodes, then use `-Gsplines=true`.

      neato -Goverlap=... -Gsplines=true -Gsep=.1

  The `sep` argument is the node-edge separation as a ratio of a node's bounding box. That is, `sep=.1` means each node is treated as though it is 1.1 times larger than it is. The actual value may require some tinkering. (Don't ask why this isn't just a constant!) Note that this option really slows down neato, so should be used sparingly and only with modest-sized graphs.

  Q. Neato runs forever on a certain example.

  First, how big is your graph? Neato is a quadratic algorithm, roughly equivalent to statistical multidimensional scaling. If you feed it a graph with thousands of nodes and edges, it can easily take hours or days. The first thing to check is to run `neato -v` to get a trace of the output. If the numbers you see are generally getting smaller, the layout is just taking a long time. You can set certain parameters, such as `epsilon` or `maxiter` to shorten the layout time, at the expense of layout quality. But if your graph is big, who's going to notice?

  If you see the numbers repeating, or fluctuating up and down, then neato is cycling, especially if your graph is small. This should never happen by default for versions later than 1.13. If it does, please report it as a bug.

  If you are using an earlier version of neato, or you used `mode=KK`, cycling is indeed possible. This cycling is very sensitive to the initial layout. By using the `start` attribute, for example,

      neato -Gstart=3
      neato -Gstart=rand

  the cycling will most likely disappear. Or you can employ the parameters used for large graphs to stop the layout earlier:

      neato -Gepsilon=.01
      neato -Gmaxiter=500

  Note that, if you have a large graph, the generation of edges as splines is a cubic algorithm, so you would do well to avoid using `splines=true`.

  Q. Edge label placement in neato is bad.

  Difficult problem. We're working on it. If anyone has some general label placement code (e.g. a simulated annealer based on the Marks et al. technique in Graphics Gems IV, please get in touch.

  Q. Dot runs forever on a certain example.

  Try dot -v to observe its progress.

  Note that it's possible to make graphs whose layout or even parsing is quadratic in the input size. For example, in dot,

      digraph G {
          a -> b -> c -> .... -> x -> y -> z
          a -> z
          b -> z
          c -> z
          /* and so on... */
      	x -> z
      }

  The total edge length (therefore the layout time) of this as a ranked graph is quadratic in the number of nodes. You probably won't encounter the following, but it is also possible to construct graphs whose parsing takes quadratic time, by appending attributes to nodes and edges after the graph has been loaded. For example:

      digraph G {
          /* really big graph goes here... */
          n0 -> n1 -> ... -> n999999999;

          n0 [attr0="whatever"]
          n0 [attr1="something else"]
          /* and so on with many more attributes */
      }

  The addition of `attr0` touches every node of the graph. Then the addition of `attr1` touches every node again, and so on.

  Q. Neato has unnecessary edge crossings, or has missed an obvious change to make a much nicer layout.

  Neato and all similar virtual physical model algorithms rely on heuristic solutions of optimization problems. The better the solution, the longer it takes to find. Unfortunately, it is also possible for these heuristics to get stuck in local minima. Also, it is heavily influenced by the initial position of the nodes. It is quite possible that if you run neato again, but with a different random seed value, or more iterations, you'll get a better layout. For example:

      neato -Gstart=5 file.dot -Tps -o file.ps
      neato -Gepsilon=.0000001 file.dot -Tps -o file.ps

  In particular, note that there are no guarantees that neato will produce a planar layout of a planar graph, or expose all or most of a graph's symmetries.

  Q. Webdot doesn't work.

  We assume you're using Apache and have TCL installed. If you don't, it's probably better to just use the webdot perl script.

  To debug webdot, first test whether `tclsh` can load the Tcldot shared library. Try:

      $ tclsh
      % load $prefix/lib/graphviz/libtcldot.so.0
      %

  where $prefix is the installation prefix for graphviz; usually /usr or /usr/local.

  Then test whether webdot runs from a shell command. (With webdot we provide a helper script scaffold.tcl or scaffold.sh that sets up an environment like the one Apache provides.) For example

      $ scaffold.tcl >out.gif
      can't read "LIBTCLDOT": no such variable
          while executing
      "file mtime $LIBTCLDOT"
          invoked from within
      "set t1 [file mtime $LIBTCLDOT]"
          (file "cgi-bin/webdot" line 67)
          invoked from within
      "source cgi-bin/webdot
      "
          (file "scaffold.tcl" line 22)

  The above is a strong clue that webdot is not configured properly properly.

  Finally, test whether webdot runs as a cgi-bin program. It may help to examine the cgi-bin environment using a simple cgi-bin tcl script like:

      	#!/bin/env tclsh
      	puts "Content-type: text/plain"
      	puts ""
      	foreach e [lsort [array names env]] {puts "$e: $env($e)"}

  Save this script as .../cgi-bin/test.tcl, make it executable, then loook at: http://localhost/cgi-bin/test.tcl

  Q. I have "Font not found" errors, or text labels missing in webdot.

  Firstly, recent versions of graphviz will use fontconfig if it is available on your platform. With fontconfig, this error should not occur, so you may want to see if an upgrade to graphviz is available, or if a rebuild will add fontconfig support.

  If fontconfig is not available then graphviz tries to resolve fontnames to fontpaths itself, and uses DOTFONTPATH (or GDFONTPATH) to indicate where it should look.

  For copyright reasons, Graphviz doesn't come with its own fonts. On a Windows machine, it knows to search in `C:\Windows\Fonts`. On a Unix machine, you need to set up a directory that contains Truetype fonts. You can get a copy of some fonts here.

  The default DOTFONTPATH is:

      #define DEFAULT_FONTPATH "/usr/X11R6/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/truetype:/usr/X11R6/lib/X11/fonts/TTF:/usr/share/fonts/TrueType:/usr/share/fonts/truetype:/usr/openwin/lib/X11/fonts/TrueType:/usr/X11R6/lib/X11/fonts/Type1"

  If your fonts are somewhere else, then you must set that directory in the webdot script, or recompile Graphviz with the correct DEFAULT_FONTPATH (or set `fontpath="/your/font/directory"` in every graph you lay out, but that's pretty clumsy.)

  Q. My browser doesn't recognize SVG.

  The correct MIME type for svg images is: `image/svg+xml` (note "+" not "-").

  SVG is not built into all browsers; you can get plugins from Adobe for Windows, Linux and some other operating systems. The Amaya browser from W3C is said to have builtin SVG. Batik is an SVG renderer in Java and can be run as a stand-alone program.

  For help with embedding SVG in HTML pages, see here. Q. libexpat is reported as containing a virus or as a security hole. Is this a real problem?

  No, this is a false positive reported by various security software. See http://www.pcreview.co.uk/forums/thread-1689630.php or http://spywareblog.com/index.php/2004/11/24/is_libexpat_dll_spyware.