File: plot_simple.py

package info (click to toggle)
python-pygraphviz 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 732 kB
  • sloc: ansic: 5,100; python: 2,669; makefile: 61
file content (30 lines) | stat: -rw-r--r-- 693 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Basic
=====

A simple example to create a graphviz dot file and draw a graph.
"""

#    Copyright (C) 2006 by
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Manos Renieris, http://www.cs.brown.edu/~er/
#    Distributed with BSD license.
#    All rights reserved, see LICENSE for details.

__author__ = """Aric Hagberg (hagberg@lanl.gov)"""

import pygraphviz as pgv

A = pgv.AGraph()

A.add_edge(1, 2)
A.add_edge(2, 3)
A.add_edge(1, 3)

print(A.string())  # print to screen
A.write("simple.dot")  # write to simple.dot

B = pgv.AGraph("simple.dot")  # create a new graph from file
B.layout()  # layout with default (neato)
B.draw("simple.png")  # draw png