Package igraph :: Module layout :: Class Layout
[hide private]
[frames] | no frames]

Class Layout

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]
 
__copy__(self)
 
__delitem__(self, idx)
 
__getitem__(self, idx)
 
__init__(self, coords=[], dim=None)
Constructor.
 
__len__(self)
 
__setitem__(self, idx, value)
 
_get_coords(self)
 
_get_dim(self)
 
append(self, value)
Appends a new point to the layout
 
bounding_box(self, border=0)
Returns the bounding box of the layout.
 
center(self, *args, **kwds)
Centers the layout around the given point.
 
centroid(self)
Returns the centroid of the layout.
 
copy(self)
Creates an exact copy of the layout.
 
mirror(self, dim)
Mirrors the layout along the given dimension(s)
 
rotate(self, degree, dim1=0, dim2=1)
Rotates the layout by the given degrees along the plane defined by the given two dimensions
 
scale(self, *args, **kwds)
Scales the layout.
 
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
 
transform(self, function, *args, **kwds)
Performs an arbitrary transformation on the layout
 
translate(self, *args, **kwds)
Translates the layout.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]
  coords
  dim

Inherited from object: __class__

Method Details [hide private]

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

 

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. An exception is thrown if the coordinate list is empty and this parameter is None. Generally, this should be given if the length of the coordinate list is zero, otherwise it should be left as is.
Raises:
  • ValueError - if the coordinate list is empty and the number of dimensions is not given.
Overrides: object.__init__

bounding_box(self, border=0)

 

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.

center(self, *args, **kwds)

 

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.

centroid(self)

 

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

mirror(self, dim)

 

Mirrors the layout along the given dimension(s)

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

scale(self, *args, **kwds)

 

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.

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

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)

 

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.

translate(self, *args, **kwds)

 

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

Property Details [hide private]

coords

Get Method:
_get_coords(self)
Set Method:
'the coordinates as a list of lists'

dim

Get Method:
_get_dim(self)
Set Method:
'the number of dimensions'