PythonGraphviz: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "= Drawing Graphs with Python + Graphviz = == Installing == <source lang="text"> sudo apt-get install python-pygraphviz </source> == Example == <source lang="python">...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
= Drawing Graphs with Python + Graphviz =
= Drawing Graphs with Python + Graphviz =
* http://networkx.lanl.gov/pygraphviz/reference/agraph.html
* http://www.graphviz.org/doc/info/attrs.html


== Installing ==
== Installing ==
Line 34: Line 37:
[[Category:Cookbook]]
[[Category:Cookbook]]


== Subgraphs ==
<source lang="python">
g = pydot.Graph()
for c in cd:
    sg = pydot.Subgraph()
    sg.set_label(c)
    g.add_subgraph(sg)
    for nn in cd[c]:
        sg.add_node(pydot.Node(str(nn)))
</source>


== Attachments ==
== Attachments ==

Latest revision as of 17:31, 4 February 2013

Drawing Graphs with Python + Graphviz

Installing

sudo apt-get install python-pygraphviz


Example

import pygraphviz

g=pygraphviz.AGraph(directed=True)
g.add_edge("a", "b")
g.add_edge("b", "c")
g.add_edge("c", "a")
g.add_edge("d", "a")

# draw the graph with various layout algorithms
g.draw('graph.png', prog="dot")
g.draw('graph2.png', prog="neato")
g.draw('graph3.png', prog="neato")


PythonGraphviz graph.png
PythonGraphviz graph2.png
PythonGraphviz graph3.png


Subgraphs

g = pydot.Graph()
for c in cd:
    sg = pydot.Subgraph()
    sg.set_label(c)
    g.add_subgraph(sg)
    for nn in cd[c]:
        sg.add_node(pydot.Node(str(nn)))

Attachments

  • PythonGraphviz graph.png
  • PythonGraphviz graph2.png
  • PythonGraphviz graph3.png