python-igraph API reference

List of all classes, functions and methods in python-igraph

class documentation

class Layout:

View In Hierarchy

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]
Method __copy__ Undocumented
Method __delitem__ Undocumented
Method __getitem__ Undocumented
Method __init__ Constructor.
Method __len__ Undocumented
Method __repr__ Undocumented
Method __setitem__ Undocumented
Method append Appends a new point to the layout
Method boundaries Returns the boundaries of the layout.
Method bounding_box Returns the bounding box of the layout.
Method center Centers the layout around the given point.
Method centroid Returns the centroid of the layout.
Method copy Creates an exact copy of the layout.
Method fit_into Fits the layout into the given bounding box.
Method mirror Mirrors the layout along the given dimension(s)
Method rotate Rotates the layout by the given degrees on the plane defined by the given two dimensions.
Method scale Scales the layout.
Method to_radial Converts a planar layout to a radial one
Method transform Performs an arbitrary transformation on the layout
Method translate Translates the layout.
Property coords The coordinates as a list of lists
Property dim Returns the number of dimensions
Instance Variable _coords Undocumented
Instance Variable _dim Undocumented
def __copy__(self):

Undocumented

def __delitem__(self, idx):

Undocumented

def __getitem__(self, idx):

Undocumented

def __init__(self, coords=None, dim=None):

Constructor.

Parameters
coordsthe coordinates to be stored in the layout.
dimthe 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.
def __len__(self):

Undocumented

def __repr__(self):

Undocumented

def __setitem__(self, idx, value):

Undocumented

def append(self, value):

Appends a new point to the layout

def boundaries(self, border=0):

Returns the boundaries of the layout.

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

Parameters
borderthis 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
ValueErrorif the layout contains no layout items
def 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
borderthis 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.
def 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
*argsUndocumented
**kwdsUndocumented
pthe point where the centroid of the layout will be after the operation.
def 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
def copy(self):

Creates an exact copy of the layout.

def fit_into(self, bbox, keep_aspect_ratio=True):

Fits the layout into the given bounding box.

The layout will be modified in-place.

Parameters
bboxthe 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_ratiowhether 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.
def mirror(self, dim):

Mirrors the layout along the given dimension(s)

Parameters
dimthe list of dimensions or a single dimension
def rotate(self, angle, dim1=0, dim2=1, **kwds):

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

Parameters
anglethe angle of the rotation, specified in degrees.
dim1the first axis of the plane of the rotation.
dim2the second axis of the plane of the rotation.
**kwdsUndocumented
originthe origin of the rotation. If not specified, the origin will be the origin of the coordinate system.
def 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
*argsUndocumented
**kwdsUndocumented
scalescaling coefficients (integer, float, list or tuple)
originthe origin of scaling (this point will stay in place). Optional, defaults to the origin of the coordinate system being used.
def 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_anglethe angle corresponding to the minimum X value
max_anglethe angle corresponding to the maximum X value
min_radiusthe radius corresponding to the minimum Y value
max_radiusthe radius corresponding to the maximum Y value
def 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
functiona function which receives the coordinates as a tuple and returns the transformed tuple.
*argsUndocumented
**kwdsUndocumented
def 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
*argsUndocumented
**kwdsUndocumented
vthe translation vector
@property
coords =

The coordinates as a list of lists

@property
dim =

Returns the number of dimensions

_coords =

Undocumented

_dim: int =

Undocumented