Package pygraphlib :: Module pydot
[show private | hide private]
[frames | no frames]

Module pygraphlib.pydot

Interface to the dot language

The pydot module provides a simple interface to the file format used in the graphviz program. The Dot class of this module is intended to offload the most tedious part of the process (the dot file generation) while transparently exposing most of its features.

In order to display graphs or to generate image files the graphviz package needs to be installed on the system, moreover the dot and dotty programs must be accesible in the program path so that they can be ran from processes spawned within the module. See the Dot documentation for further information on the setup.

Example usage

>>> from pygraphlib import pygraph, pydot
>>> edges = [ (1,2), (2,3), (3,4), (3,5), (4,5), (5,1) ]
>>> graph = pygraph.from_list(edges)
>>> print graph
UGraph: 5 nodes, 6 edges

>>> dot = pydot.Dot(graph)
>>> dot.save_image('pydot_example1.gif', mode='gif')

Customizing the output

The graph drawing process may be customized by passing valid dot parameters for the nodes and edges.
>>> dot = pydot.Dot(graph)
>>> # this sets the overall style of the graph
>>> dot.set_style(size='10,10', rankdir='RL', page='20, 20' , ranksep=0.75)
>>> # customize some nodes
>>> dot.set_node_style(1, label='BASE NODE',shape='box', color='blue' )
>>> dot.set_node_style(2, style='filled', fillcolor='red')
>>> # customizing edge drawing
>>> dot.set_edge_style(1, 2, style='dotted')
>>> dot.set_edge_style(3, 5, arrowhead='dot', label='binds', labelangle='90')
>>> dot.set_edge_style(4, 5, arrowsize=2, style='bold')
>>> # creates the image
>>> dot.save_image('pydot_example2.gif', mode='gif')
Observation: dotty (invoked via Dot.show()) may not be able to display all graphics styles. To verify the output save it to an image file and look at it that way.

Valid attributes

drawing process see the graphviz manual.
Classes
Dot A class that creates a graphviz (dot language) representation of the graph.

Generated by Epydoc 2.1 on Wed Jan 5 09:38:28 2005 http://epydoc.sf.net