Drawing

NetworkX provides interfaces to two packages for graph drawing.

Matplotlib

To use the NetworkX matplotlib interface you need:

Follow the instructions at http://matplotlib.sourceforge.net/installing.html to install the software.

Graphviz

NetworkX provides an interface to pydot to write graphs in the dot language. The resulting "dot" files can be processed using the graphviz tool kit to make graph drawings in many different styles and output formats.

To use the graphviz interface you need:

Pydot has a known bug in parsing double quoted strings and in representing the special graphviz null symbol '\N'. In order for it to work properly with NetworkX you must apply this patch (or make the changes yourself in dot_parser.py).

Using

>>> from networkx import *
>>> G=tetrahedral_graph()

Draw with matplotlib

>>> draw(G)
>>> savefig("tetrahedral.png")
>>> show()
tetrahedral-s.png

Write a dot language file:

>>> write_dot(G,"tetrahedral.dot")
graph G {
node [label="\N"];
graph [bb="0,0,138,252"];
1 [pos="73,234", width="0.75", height="0.50"];
2 [pos="73,162", width="0.75", height="0.50"];
3 [pos="27,90", width="0.75", height="0.50"];
4 [pos="82,18", width="0.75", height="0.50"];
1 -- 2 [pos="73,216 73,205 73,191 73,180"];
1 -- 3 [pos="59,218 51,208 42,194 37,180 28,156 27,127 26,108"];
1 -- 4 [pos="87,218 95,208 104,194 109,180 124,129 103,65 90,35"];
2 -- 3 [pos="62,145 55,134 45,118 38,107"];
2 -- 4 [pos="74,144 76,116 79,64 81,36"];
3 -- 4 [pos="39,74 48,62 61,46 70,34"];
}