python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Module layout :: Class Layout
[hide private]

Class Layout

source code

object --+
         |
        Layout

Represents the layout of a graph.

A layout is practically a list of coordinates in an n-dimensional space. This class is generic in the sense that it can store coordinates in any n-dimensional space.

Layout objects are not associated directly with a graph. This is deliberate: there were times when I worked with almost identical copies of the same graph, the only difference was that they had different colors assigned to the vertices. It was particularly convenient for me to use the same layout for all of them, especially when I made figures for a paper. However, igraph will of course refuse to draw a graph with a layout that has less coordinates than the node count of the graph.

Layouts behave exactly like lists when they are accessed using the item index operator ([...]). They can even be iterated through. Items returned by the index operator are only copies of the coordinates, but the stored coordinates can be modified by directly assigning to an index.

>>> layout = Layout([(0, 1), (0, 2)])
>>> coords = layout[1]
>>> print coords
[0, 2]
>>> coords = (0, 3)
>>> print layout[1]
[0, 2]
>>> layout[1] = coords
>>> print layout[1]
[0, 3]
Instance Methods [hide private]
 
__init__(self, coords=None, dim=None)
Constructor.
source code
 
__len__(self) source code
 
__getitem__(self, idx) source code
 
__setitem__(self, idx, value) source code
 
__delitem__(self, idx) source code
 
__copy__(self) source code
 
__repr__(self)
repr(x)
source code
 
append(self, value)
Appends a new point to the layout
source code
 
mirror(self, dim)
Mirrors the layout along the given dimension(s)
source code
 
rotate(self, angle, dim1=0, dim2=1, **kwds)
Rotates the layout by the given degrees on the plane defined by the given two dimensions.
source code
 
scale(self, *args, **kwds)
Scales the layout.
source code
 
translate(self, *args, **kwds)
Translates the layout.
source code
 
to_radial(self, min_angle=100, max_angle=80, min_radius=0.0, max_radius=1.0)
Converts a planar layout to a radial one
source code
 
transform(self, function, *args, **kwds)
Performs an arbitrary transformation on the layout
source code
 
centroid(self)
Returns the centroid of the layout.
source code
 
boundaries(self, border=0)
Returns the boundaries of the layout.
source code
 
bounding_box(self, border=0)
Returns the bounding box of the layout.
source code
 
center(self, *args, **kwds)
Centers the layout around the given point.
source code
 
copy(self)
Creates an exact copy of the layout.
source code
 
fit_into(self, bbox, keep_aspect_ratio=True)
Fits the layout into the given bounding box.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  dim
Returns the number of dimensions
  coords
The coordinates as a list of lists

Inherited from object: __class__

Method Details [hide private]

__init__(self, coords=None, dim=None)
(Constructor)

source code 

Constructor.

Parameters:
  • coords - the coordinates to be stored in the layout.
  • dim - the number of dimensions. If None, the number of dimensions is determined automatically from the length of the first item of the coordinate list. If there are no entries in the coordinate list, the default will be 2. Generally, this should be given if the length of the coordinate list is zero, otherwise it should be left as is.
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

mirror(self, dim)

source code 

Mirrors the layout along the given dimension(s)

Parameters:
  • dim - the list of dimensions or a single dimension

rotate(self, angle, dim1=0, dim2=1, **kwds)

source code 

Rotates the layout by the given degrees on the plane defined by the given two dimensions.

Parameters:
  • angle - the angle of the rotation, specified in degrees.
  • dim1 - the first axis of the plane of the rotation.
  • dim2 - the second axis of the plane of the rotation.
  • origin - the origin of the rotation. If not specified, the origin will be the origin of the coordinate system.

scale(self, *args, **kwds)

source code 

Scales the layout.

Scaling parameters can be provided either through the scale keyword argument or through plain unnamed arguments. If a single integer or float is given, it is interpreted as a uniform multiplier to be applied on all dimensions. If it is a list or tuple, its length must be equal to the number of dimensions in the layout, and each element must be an integer or float describing the scaling coefficient in one of the dimensions.

Parameters:
  • scale - scaling coefficients (integer, float, list or tuple)
  • origin - the origin of scaling (this point will stay in place). Optional, defaults to the origin of the coordinate system being used.

translate(self, *args, **kwds)

source code 

Translates the layout.

The translation vector can be provided either through the v keyword argument or through plain unnamed arguments. If unnamed arguments are used, the vector can be supplied as a single list (or tuple) or just as a series of arguments. In all cases, the translation vector must have the same number of dimensions as the layout.

Parameters:
  • v - the translation vector

to_radial(self, min_angle=100, max_angle=80, min_radius=0.0, max_radius=1.0)

source code 

Converts a planar layout to a radial one

This method applies only to 2D layouts. The X coordinate of the layout is transformed to an angle, with min(x) corresponding to the parameter called min_angle and max(y) corresponding to max_angle. Angles are given in degrees, zero degree corresponds to the direction pointing upwards. The Y coordinate is interpreted as a radius, with min(y) belonging to the minimum and max(y) to the maximum radius given in the arguments.

This is not a fully generic polar coordinate transformation, but it is fairly useful in creating radial tree layouts from ordinary top-down ones (that's why the Y coordinate belongs to the radius). It can also be used in conjunction with the Fruchterman-Reingold layout algorithm via its miny and maxy parameters (see Graph.layout_fruchterman_reingold) to produce radial layouts where the radius belongs to some property of the vertices.

Parameters:
  • min_angle - the angle corresponding to the minimum X value
  • max_angle - the angle corresponding to the maximum X value
  • min_radius - the radius corresponding to the minimum Y value
  • max_radius - the radius corresponding to the maximum Y value

transform(self, function, *args, **kwds)

source code 

Performs an arbitrary transformation on the layout

Additional positional and keyword arguments are passed intact to the given function.

Parameters:
  • function - a function which receives the coordinates as a tuple and returns the transformed tuple.

centroid(self)

source code 

Returns the centroid of the layout.

The centroid of the layout is the arithmetic mean of the points in the layout.

Returns:
the centroid as a list of floats

boundaries(self, border=0)

source code 

Returns the boundaries of the layout.

The boundaries are the minimum and maximum coordinates along all dimensions.

Parameters:
  • border - this value gets subtracted from the minimum bounds and gets added to the maximum bounds before returning the coordinates of the box. Defaults to zero.
Returns:
the minimum and maximum coordinates along all dimensions, in a tuple containing two lists, one for the minimum coordinates, the other one for the maximum.
Raises:
  • ValueError - if the layout contains no layout items

bounding_box(self, border=0)

source code 

Returns the bounding box of the layout.

The bounding box of the layout is the smallest box enclosing all the points in the layout.

Parameters:
  • border - this value gets subtracted from the minimum bounds and gets added to the maximum bounds before returning the coordinates of the box. Defaults to zero.
Returns:
the coordinates of the lower left and the upper right corner of the box. "Lower left" means the minimum coordinates and "upper right" means the maximum. These are encapsulated in a BoundingBox object.

center(self, *args, **kwds)

source code 

Centers the layout around the given point.

The point itself can be supplied as multiple unnamed arguments, as a simple unnamed list or as a keyword argument. This operation moves the centroid of the layout to the given point. If no point is supplied, defaults to the origin of the coordinate system.

Parameters:
  • p - the point where the centroid of the layout will be after the operation.

fit_into(self, bbox, keep_aspect_ratio=True)

source code 

Fits the layout into the given bounding box.

The layout will be modified in-place.

Parameters:
  • bbox - the bounding box in which to fit the layout. If the dimension of the layout is d, it can either be a d-tuple (defining the sizes of the box), a 2d-tuple (defining the coordinates of the top left and the bottom right point of the box), or a BoundingBox object (for 2D layouts only).
  • keep_aspect_ratio - whether to keep the aspect ratio of the current layout. If False, the layout will be rescaled to fit exactly into the bounding box. If True, the original aspect ratio of the layout will be kept and it will be centered within the bounding box.

Property Details [hide private]

dim

Returns the number of dimensions

Get Method:
unreachable.dim(self) - Returns the number of dimensions

coords

The coordinates as a list of lists

Get Method:
unreachable.coords(self) - The coordinates as a list of lists

   Home       Trees       Indices       Help