List of all classes, functions and methods in python-igraph
class 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]
Method | __init__ |
Constructor. |
Method | __len__ |
Undocumented |
Method | __getitem__ |
Undocumented |
Method | __setitem__ |
Undocumented |
Method | __delitem__ |
Undocumented |
Method | __copy__ |
Undocumented |
Method | __repr__ |
Undocumented |
Property | dim |
Returns the number of dimensions |
Property | coords |
The coordinates as a list of lists |
Method | append |
Appends a new point to the layout |
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 | translate |
Translates the layout. |
Method | to_radial |
Converts a planar layout to a radial one |
Method | transform |
Performs an arbitrary transformation on the layout |
Method | centroid |
Returns the centroid of 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 | copy |
Creates an exact copy of the layout. |
Method | fit_into |
Fits the layout into the given bounding box. |
Instance Variable | _coords |
Undocumented |
Instance Variable | _dim |
Undocumented |
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. |
Mirrors the layout along the given dimension(s)
Parameters | dim | the list of dimensions or a single dimension |
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. | |
kwds | Undocumented | |
origin | the origin of the rotation. If not specified, the origin will be the origin of the coordinate system. |
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 | args | Undocumented |
kwds | Undocumented | |
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. |
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 | args | Undocumented |
kwds | Undocumented | |
v | the translation vector |
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 |
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. |
args | Undocumented | |
kwds | Undocumented |
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 |
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 |
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. |
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 | args | Undocumented |
kwds | Undocumented | |
p | the point where the centroid of the layout will be after the operation. |
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. |