thirdparty/python-graph/examples/draw.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 29 Nov 2008 00:12:47 +0000
changeset 606 65d35584ee31
parent 594 06c2228e39cb
permissions -rw-r--r--
Make forms generic Currently only Sponsor uses the new generic forms, as such this makes the form code more complex. The other forms, however, can be converted in a similar way, which will result in a lot of code reduction. Patch by: Sverre Rabbelier

#!/usr/bin/env python

# Copyright (c) 2007-2008 Pedro Matiello <pmatiello@gmail.com>
# License: MIT (see COPYING file)

import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz/python/')
import graph
import gv

# Graph creation
gr = graph.graph()

# Add nodes and edges
gr.add_nodes(["Portugal","Spain","France","Germany","Belgium","Netherlands","Italy"])
gr.add_node("England")
gr.add_node("Ireland")
gr.add_node("Scotland")
gr.add_node("Wales")

gr.add_edge("Portugal", "Spain")
gr.add_edge("Spain","France")
gr.add_edge("France","Belgium")
gr.add_edge("France","Germany")
gr.add_edge("France","Italy",)
gr.add_edge("Belgium","Netherlands")
gr.add_edge("Germany","Belgium")
gr.add_edge("Germany","Netherlands")
gr.add_edge("England","Wales")
gr.add_edge("England","Scotland")
gr.add_edge("Scotland","Wales")

# Print to DOT Language
dot = gr.write(fmt='dot')
print dot

# Print graph as PNG image
gvv = gv.readstring(dot)
gv.layout(gvv,'neato')
gv.render(gvv,'png','graph.png')