Package igraph :: Module drawing
[hide private]
[frames] | no frames]

Module drawing

Drawing and plotting routines for IGraph.

Plotting is dependent on the pycairo library which provides Python bindings to the popular Cairo library. This means that if you don't have pycairo installed, you won't be able to use the plotting capabilities. However, you can still use Graph.write_svg to save the graph to an SVG file and view it from Mozilla Firefox (free) or edit it in Inkscape (free), Skencil (formerly known as Sketch, also free) or Adobe Illustrator (not free, therefore I'm not linking to it :)).


License: Copyright (C) 2006-2007 Gabor Csardi <csardi@rmki.kfki.hu>, Tamas Nepusz <ntamas@rmki.kfki.hu> MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Classes [hide private]
  BoundingBox
Class representing a bounding box (a rectangular area).
  CircleDrawer
Static class which draws circular vertices
  CoordinateSystem
Class implementing a coordinate system object.
  DescartesCoordinateSystem
Class implementing a 2D Descartes coordinate system object.
  DownTriangleDrawer
Static class which draws triangles pointing down
  NullDrawer
Static drawer class which draws nothing.
  Plot
Class representing an arbitrary plot
  RectangleDrawer
Static class which draws rectangular vertices
  ShapeDrawer
Static class, the ancestor of all vertex shape drawer classes.
  UpTriangleDrawer
Static class which draws upright triangles
Functions [hide private]
 
collect_attributes(n, name, alt_name, kwds, vs, config, default, transform=None)
Collects graph visualization attributes from various sources.
 
draw_shape_path(shape, ctx, cx, cy, w, h=None)
Draws a path of a shape on the given Cairo context.
 
plot(obj, target=None, bbox=(0, 0, 600, 600), *args, **kwds)
Plots the given object to the given target.
Variables [hide private]
  __loader__ = <zipimporter object "/Library/Python/2.5/site-pac...
  known_shapes = {'': <class 'igraph.drawing.NullDrawer'>, 'arro...
Function Details [hide private]

collect_attributes(n, name, alt_name, kwds, vs, config, default, transform=None)

 

Collects graph visualization attributes from various sources.

This method is used by Graph.__plot__ to collect the attributes required for graph visualization from various sources. Attribute value sources are:

  • A specific value of a Python dict belonging to a given key. This dict is given by the argument kwds, and the name of the key is determined by the argument name.
  • A vertex or edge sequence of a graph, given in vs
  • The global configuration, given in config
  • A default value when all other sources fail to provide the value. given in default

Attribute sources are considered exactly in the order mentioned above. Optionally, the retrieved value is passed through an arbitrary transformation.

Returns:
the collected attributes

draw_shape_path(shape, ctx, cx, cy, w, h=None)

 

Draws a path of a shape on the given Cairo context.

Parameters:
  • shape - the shape to be drawn
  • ctx - the context to draw on
  • cx - X coordinate of the center of the shape
  • cy - Y coordinate of the center of the shape
  • w - desired width of the shape
  • h - desired height of the shape. If omitted, defaults to the width.

plot(obj, target=None, bbox=(0, 0, 600, 600), *args, **kwds)

 

Plots the given object to the given target.

Positional and keyword arguments not explicitly mentioned here will be passed down to the __plot__ method of the object being plotted. Since you are most likely interested in the keyword arguments available for graph plots, see Graph.__plot__ as well.

Parameters:
  • obj - the object to be plotted
  • target - the target where the object should be plotted. It can be one of the following types:
    • None -- an appropriate surface will be created and the object will be plotted there.
    • cairo.Surface -- the given Cairo surface will be used. This can refer to a PNG image, an arbitrary window, an SVG file, anything that Cairo can handle.
    • string -- a file with the given name will be created and an appropriate Cairo surface will be attached to it.
  • bbox - the bounding box of the plot. It must be a tuple with four integers, the first two denoting the X and Y coordinates of a corner and the latter two denoting the X and Y coordinates of the opposite corner. It can also be a BoundingBox object.
  • opacity - the opacity of the object being plotted. It can be used to overlap several plots of the same graph if you use the same layout for them -- for instance, you might plot a graph with opacity 0.5 and then plot its spanning tree over it with opacity 0.1. To achieve this, you'll need to modify the Plot object returned with Plot.add.
Returns:
an appropriate Plot object.

See Also: Graph.__plot__


Variables Details [hide private]

__loader__

Value:
<zipimporter object "/Library/Python/2.5/site-packages/python_igraph-0\
.5.1-py2.5-macosx-10.5-i386.egg/igraph/">

known_shapes

Value:
{'': <class 'igraph.drawing.NullDrawer'>,
 'arrow-down': <class 'igraph.drawing.DownTriangleDrawer'>,
 'arrow-up': <class 'igraph.drawing.UpTriangleDrawer'>,
 'box': <class 'igraph.drawing.RectangleDrawer'>,
 'circle': <class 'igraph.drawing.CircleDrawer'>,
 'circular': <class 'igraph.drawing.CircleDrawer'>,
 'down-arrow': <class 'igraph.drawing.DownTriangleDrawer'>,
 'empty': <class 'igraph.drawing.NullDrawer'>,
...