Skip navigation

I love writing graphs. It might sound oxymoron to you. graphs and writing. But it’s possible. And I’ve been doing that even in last evening. If you are anything like me, you want me to spit out how to do that. And that’s exactly what I’m going to do.

I met Graphviz an year back, when I was looking for a tool to draw graphs. I was taking “Database Management Systems” module and I had an assignment to draw boring diagrams. Drawing those with word processing software only made it more boring. Graphviz really made it fun to draw diagrams. Because it took the “drawing” out of “drawing graphs”. I only had to write code.

Graphviz is an open source graph visualizing tool. It comes with set of tools that helps you write down instructions how your graph should be and get your grph drawn in pdf, jpeg, postscript and many other formats. There are graph definition languages called dot, neato, fdp etc. I have only worked with dot and neato. Mostly dot.

Since I’m doing quite ok with programming, I found it fairly easy to get started with Graphviz (dot, specifically). It was the day before an assignment submission and I did complete the whole task, designing the database diagrams and drawing them using dot in fairly little time. This included learning a totally new tool, dot. I was under a lot of pressure but dot didn’t add a lot of weight. True story.

So anyhow, I had to draw few graphs for a recent assignment. And I wanted to go back to Graphviz. So I installed Graphviz and read the manual. And I was writing graphs so quick, again.

You can install graphviz on ubuntu so easily.
sudo aptitude install graphviz

And you can draw graphs like this.

Above graph is made with following dot source. dot source files have the extension .dot.

digraph example{
node [shape = circle]; //setting default node shape to circle

"Twitter" -> "cool" [label = "is"]; //An edge with a label
"chanux" -> "Twitter" [label = "loves", style=bold]; //An edge that is bold
"chanux" -> "Blog" [label = "Also loves"];

//define which nodes are on same level
{rank = same; "Twitter"; "Blog";};

"chanux" [penwidth = 3];

//Use a different label for a node
"Blog" [label = "His Blog"];

//Add color to node
"Twitter" [color = "darkslategray2", style = filled];

//Hack to add labels for nodes outside the nodes
"Blog" -> "Blog" [label = "This is awesome." color = transparent];

You can get the .jpeg output by running following command.
dot -T jpeg -o mygraph.jpg

And for a pdf output
dot -T pdf mygraph.pdf

What I have shown only a little bit of what graphviz can do. There are more examples on graphviz site. There are areas where graphviz is still not doing good (ex: less control over label placement). But it’s quite fascinating to write graphs with it. The dotguide [pdf] is a good place to from. Hope you’d find it cool. Hpappy graph writing!


  1. This is cool! Should give a try.

  2. thanks pretty nice. i discovered that it is also possible to define custom shapes with shape=custom
    shapefile=”hello.png” thats pretty awesome to do custom visualisations of structures.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: