Drawing
========

NetworkX provides interfaces to two packages for graph drawing,
matplotlib and graphviz.

Matplotlib
----------

To use the NetworkX matplotlib interface you need: 

   - Matplotlib version 0.73.1 or later  http://matplotlib.sourceforge.net/

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

Graphviz
--------

NetworkX provides an interface to graphviz 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:

   - Graphviz, version 2.0 or later  http://graphviz.org/

and one of either pygraphviz or pydot (with this patch_)

Pygraphviz
~~~~~~~~~~

Pygraphviz is a Python wrapper to the graphviz Agraph data structure.
The C code in the graphviz library is wrapped using SWIG.

   - Pygraphviz, version 0.21 or later  http://networkx.lanl.gov/pygraphviz/

Pydot
~~~~~
Pydot is a pure Python interface to graphviz.  	

   - Pydot, version 0.9.10 or later  http://www.dkbza.org/pydot.html
   - Pyparsing, version 1.3 or later http://pyparsing.sourceforge.net/

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).

.. _patch: pydot-quote.patch



Using 
-----

>>> import networkx as NX
>>> G=NX.tetrahedral_graph()

Draw with matplotlib:

>>> import pylab as P
>>> NX.draw(G)
>>> P.savefig("tetrahedral.png")
>>> P.show()

.. raw:: html

   <div align="left" class="image image align-left image-reference">
    <img align="left" alt="NetworkX" class="image" height="600"
    src="https://networkx.lanl.gov/images/tetrahedral-s.png"  width="800" />
    </div>
    <br clear=both></br>

Write a dot language file:

>>> NX.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"];
        }

