Graphviz: How to go from .dot to a graph?
Asked Answered
M

12

581

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)

Meletius answered 29/9, 2009 at 19:34 Comment(1)
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.Enclave
U
580

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 for more detail on how to use the tools: https://www.graphviz.org/documentation/

See section "Command Line Options" for output formatting for the dot command, for instance: https://www.graphviz.org/pdf/dotguide.pdf

Undertake answered 29/9, 2009 at 19:35 Comment(8)
somehow, the GVEdit preview always shows the image to be blank. When I try to save the image, nothing happens.Meletius
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!Bellflower
@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 pageHecto
AFAIK, it is not possible to make GVEdit remember the windows. I agree the UX leaves something to be desired.Undertake
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.Ridgeling
This is wrong. You change the extension passed to the -T flag. The "extension" on the end of the filename is meaninglessComet
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.Gitt
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. The layouts are not always identical.Thickening
R
282
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.

Repertory answered 29/9, 2009 at 19:43 Comment(4)
instead of using >, I suggest to use the « -o » parameterBuyse
Depending on what support your system has, you can export to all sorts of file formats. I found dot -Tsvg input.dot > output.svg quite useful.Alcoholize
Slightly easier, let dot chose the filename based on input filename and file type: dot -Tpng -O file.dot (will produce file.png)Weiss
Same command is working in macOS, via macports. :)Null
L
116

dot file.dot -Tpng -o image.png

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

Lafountain answered 11/1, 2013 at 19:15 Comment(4)
Add Graphviz to PathPickerelweed
On OSX, you'll need to install Graphviz first using Homebrew: brew install graphvizHaws
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?Manganous
1. Install Graphviz from 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'Unwholesome
O
60

There are also the online viewers:

Otero answered 20/10, 2013 at 18:16 Comment(3)
I totally made Erdos and forgot about it ages ago. I had no idea how many people linked to it!Spital
add a donate button ;)Flatware
I am trying to generate a graph for the C grammar from here quut.com/c/ANSI-C-grammar-y.html. But it's not successful. Is this grammar too big to be handled?Ratter
S
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.

Streptothricin answered 29/9, 2009 at 20:16 Comment(1)
Lots of features, but an absolutely crazy interface design!Strachey
B
29

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
Bos answered 29/9, 2018 at 18:58 Comment(0)
U
10

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

Unwholesome answered 15/1, 2020 at 11:51 Comment(0)
S
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.

Socinus answered 18/9, 2012 at 12:27 Comment(0)
W
8

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

Whiten answered 7/10, 2019 at 10:40 Comment(1)
Thanks a lot, I was feeling dumb not getting my hands on the viewer version of dot ! :)Holle
A
4

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

Agential answered 1/9, 2022 at 9:58 Comment(1)
somehow PDF is the only one working for meBlynn
G
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

Gradate answered 31/5, 2018 at 8:22 Comment(0)
F
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.

Flack answered 8/3, 2019 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.