565

I can't seem to figure this out. I have a .dot file, which is valid according to the syntax. How do I use graphviz to convert this into an image?

(note that I'm on Windows, not linux)

CodeFreezr
  • 362
  • 2
  • 18
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
  • 19
    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.. It doesn't say anything, you just find the file in the same directory as your .dot file. – ashley Mar 26 '15 at 09:15

12 Answers12

568

type: dot -Tps filename.dot -o outfile.ps

If you want to use the dot renderer. There are alternatives like neato and twopi. If graphiz isn't in your path, figure out where it is installed and run it from there.

You can change the output format by varying the value after -T and choosing an appropriate filename extension after -o.

If you're using windows, check out the installed tool called GVEdit, it makes the whole process slightly easier.

Go look at the graphviz site in the section called "User's Guides" for more detail on how to use the tools:

http://www.graphviz.org/documentation/

(See page 27 for output formatting for the dot command, for instance)

http://www.graphviz.org/pdf/dotguide.pdf

Paul McMillan
  • 19,693
  • 9
  • 57
  • 71
  • 2
    somehow, the GVEdit preview always shows the image to be blank. When I try to save the image, nothing happens. – Nick Heiner Sep 29 '09 at 20:05
  • 8
    Is it possible to make GVEdit remember the size and location of the Layout windows? It drives me nuts that when I press F5 it always shrinks the size of the layout window back to default! – Matthew Lock Aug 23 '12 at 01:51
  • @PaulMcMillan, could you help me out with m problem here: `http://stackoverflow.com/questions/26477403/graphviz-dot-to-ps-issue`, my output is bounded to a fix page and some parts are out of the page – Amir Oct 21 '14 at 22:04
  • AFAIK, it is not possible to make GVEdit remember the windows. I agree the UX leaves something to be desired. – Paul McMillan Dec 04 '14 at 22:29
  • I made a terraform.dot file from a terraform graph command. I'm on windows. i did -o outfile.jpg and when I double click the jpg it locks up explorer. Tried gif also and got same issue. – JDPeckham Apr 06 '18 at 02:55
  • This is wrong. You change the extension passed to the -T flag. The "extension" on the end of the filename is meaningless – Jefferson Hudson Sep 13 '19 at 17:33
  • You CANNOT change the output format by simply changing the file extension - you MUST specify the type with the -T option. Without the -T option, graphviz (which I think is great, BTW) will simply ignore the file extension, except, of course, your file will be named that way, but NOT be of the format you want. – John Deighan Mar 30 '20 at 13:49
  • 2
    The gvedit binary is not included in versions later than 2.38 due to copyright restrictions. A more polished interface is available in the similar [Msc-generator](https://sourceforge.net/projects/msc-generator). The layouts are not always identical. – Pekka Sep 19 '21 at 06:29
271
dot -Tps input.dot > output.eps
dot -Tpng input.dot > output.png

PostScript output seems always there. I am not sure if dot has PNG output by default. This may depend on how you have built it.

user172818
  • 4,518
  • 1
  • 18
  • 20
113

dot file.dot -Tpng -o image.png

This works on Windows and Linux. Graphviz must be installed.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
jbp
  • 1,581
  • 1
  • 10
  • 15
  • 2
    Add Graphviz to Path – Anupama G Feb 08 '16 at 06:05
  • 11
    On OSX, you'll need to install Graphviz first using Homebrew: `brew install graphviz` – Dennis Jul 22 '16 at 10:40
  • 1
    I can generate a png image with dot, but the background is white in color. I need a transparent background. Is there any way to get it? – Sujai Sivasamy Nov 20 '17 at 12:03
  • 1
    1. Install Graphviz from https://graphviz.gitlab.io/_pages/Download/Download_windows.html 2. Add 'C:\Program Files (x86)\Graphviz2.38\bin' to your system variable PATH 3. Open cmd and go to the dir where you saved the .dot file 4. Use the command 'dot yourFile.dot -Tpng -o image.png' – Subhashi Jan 15 '20 at 11:42
56

There's also the online viewers:

ArtemGr
  • 11,684
  • 3
  • 52
  • 85
34

Get the graphviz-2.24.msi Graphviz.org. Then get zgrviewer.

Zgrviewer requires java (probably 1.5+). You might have to set the paths to the Graphviz binaries in Zgrviewer's preferences.

File -> Open -> Open with dot -> SVG pipeline (standard) ... Pick your .dot file.

You can zoom in, export, all kinds of fun stuff.

user
  • 5,335
  • 7
  • 47
  • 63
Seth
  • 45,033
  • 10
  • 85
  • 120
27

This should combine a lot of answers.

# Convert dot to png via graphviz
dot -Tpng filename.dot -o filename.png

# Convert dot to svg via graphviz
dot -Tsvg filename.dot -o filename.svg

# Convert dot to eps via graphviz
dot -Tps filename.dot -o filename.eps

Keep in mind that on OSX (MAC), you need to install homebrew to install graphviz to be able to use the dot commands above.

brew install graphviz

It is also possible to install Graphviz (and use the commands above) through the package manager functionality of conda if you have Anaconda installed.

conda install python-graphviz
9

You can also output your file in xdot format, then render it in a browser using canviz, a JavaScript library.

Canviz on code.google.com:

To see an example, there is a "Canviz Demo" link on the page above as of November 2, 2014.

innohead
  • 344
  • 2
  • 3
9

You can use the VS code and install the Graphviz extension or,

  1. Install Graphviz from https://graphviz.gitlab.io/_pages/Download/Download_windows.html
  2. Add C:\Program Files (x86)\Graphviz2.38\bin (or your_installation_path/ bin) to your system variable PATH
  3. Open cmd and go to the dir where you saved the .dot file
  4. Use the command dot music-recommender.dot -Tpng -o image.png

enter image description here

Subhashi
  • 4,145
  • 1
  • 23
  • 22
7

there is no requirement of any conversion.

We can simply use xdot command in Linux which is an Interactive viewer for Graphviz dot files.

ex: xdot file.dot

for more infor:https://github.com/rakhimov/cppdep/wiki/How-to-view-or-work-with-Graphviz-Dot-files

Luftatako
  • 121
  • 1
  • 2
  • Thanks a lot, I was feeling dumb not getting my hands on the viewer version of dot ! :) – Xenos May 17 '20 at 17:24
3

For window user, Please run complete command to convert *.dot file to png:

C:\Program Files (x86)\Graphviz2.38\bin\dot.exe" -Tpng sampleTest.dot > sampletest.png.....

I have found a bug in solgraph that it is utilizing older version of solidity-parser that does not seem to be intelligent enough to capture new enhancement done for solidity programming language itself e.g. emit keyword for Event

ADyson
  • 57,178
  • 14
  • 51
  • 63
Abhishek Jain
  • 3,815
  • 2
  • 26
  • 26
3

You can use a very good online tool for it. Here is the link dreampuf.github.io Just replace the code inside editer with your code.

Sanaullah Ahmad
  • 474
  • 4
  • 12
3

$ dot -T pdf filename.dot > filename.pdf This works on my Windows 10.

Subfire
  • 79
  • 2
  • 5