Rcjp's Weblog

January 11, 2007

Quick Graphviz Test

Filed under: python — rcjp @ 10:14 am

I occassionally need something to show a connection graph and graphviz is a handy tool especially using the python pydot interface, just define some node links…

    r@laptop:~/src/python/pydot-0.9.10$ sudo python setup.py install
    running install
    running build
    running build_py
    creating build
    creating build/lib
    copying pydot.py -> build/lib
    copying dot_parser.py -> build/lib
    running install_lib
    copying build/lib/pydot.py -> /usr/lib/python2.4/site-packages
    copying build/lib/dot_parser.py -> /usr/lib/python2.4/site-packages
    byte-compiling /usr/lib/python2.4/site-packages/pydot.py to pydot.pyc
    byte-compiling /usr/lib/python2.4/site-packages/dot_parser.py to dot_parser.pyc


then, running in ipython

    In [35]: import pydot

    In [36]: edges=[(1,2), (1,3), (1,4), (3,4)]

    In [37]: g=pydot.graph_from_edges(edges)

    In [38]: g.write_png('test-graph.png', prog='dot')
    Out[38]: True


test-graph

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: