GraphViz for discrete math students


General Information, and Links to more detailed References

Graphs and Vertices (Called Nodes in the GraphViz notation) may have a large number of attributes that affect both the graph's actual layout, and details like colours, labels, line types, etc. I cover a few of the attributes below but for a full reference see The GraphViz Attribute Index, It's a bit tricky to read at first but really not too complicated, and it's very comprehensive.

Important Attributes

I have found the following attributes to be particularily useful in my classes

Graph Attributes

Vertex Attributes

Edge Attributes

Edges may also have a weight attribute, defined as [weight=0.5] for example, but note that this doesn't display the weight directly, It instead acts as a hint to the graph layout to give this edge a more direct routing.


Graphs are defined as either a graph or a digraph using fairly standard syntax, similar to an edge list.

graph { node1 -- node2; node3 -- node2; }
digraph { node1 -> node2; node3 -> node2; }


Vertices are defined with a simple plaintext label, A, B, C, Test, Vertice1, some_vertex, etc. If you need a more complicated label you can declare the vertex first, before defining an edge, and give it a label attribute, for example:
digraph { someVertex[label="A Complicated Label"]; someVertex -> node2; node2 -> node3; }


For the most part the only concern with edges is their colour/thickness, and Label, as the rest is handled automatically by the graph/digraph definition, To color an edge apply the color attribute to the graph definition as follows
digraph { node1 -> node2[color="red"]; }
To Display a weight, we give the vertex itself a label, similar to how we label nodes
digraph { node1 -> node2[label="0.2"]; node2 -> node3[label="0.2"]; }
We can actually apply any label we like to edge in this way digraph { node1 -> node2[label="edge1"]; node2 -> node3[label="edge2"]; }
You may combine these attributes in any way you please
digraph { node1[label="Some Complicated Label"]; node1 -> node2[label="An Edge",color=red]; node2 -> node3; }