module documentation

Layout-related code in the igraph library.

This package contains the implementation of the Layout object.

Class Layout Represents the layout of a graph.
Function align_layout Aligns a graph layout with the coordinate axes
Function _3d_version_for Creates an alias for the 3D version of the given layout algoritm.
Function _layout Returns the layout of the graph according to a layout algorithm.
Function _layout_auto Chooses and runs a suitable layout function based on simple topological properties of the graph.
Function _layout_method_wrapper Wraps an existing layout method to ensure that it returns a Layout instead of a list of lists.
Function _layout_sugiyama Places the vertices using a layered Sugiyama layout.
Variable _layout_mapping Undocumented
def align_layout(graph, layout): (source)

Aligns a graph layout with the coordinate axes

This function centers a vertex layout on the coordinate system origin and rotates the layout to achieve a visually pleasing alignment with the coordinate axes. Doing this is particularly useful with force-directed layouts such as Graph.layout_fruchterman_reingold. Layouts in arbitrary dimensional spaces are supported.

Parameters
graphthe graph that the layout is associated with.
layoutthe Layout object containing the vertex coordinates to align.
Returns
a new aligned Layout object.
def _3d_version_for(func): (source)

Creates an alias for the 3D version of the given layout algoritm.

This function is a decorator that creates a method which calls func after attaching dim=3 to the list of keyword arguments.

Parameters
funcmust be a method of the Graph object.
Returns
a new method
def _layout(graph, layout=None, *args, **kwds): (source)

Returns the layout of the graph according to a layout algorithm.

Parameters and keyword arguments not specified here are passed to the layout algorithm directly. See the documentation of the layout algorithms for the explanation of these parameters.

Registered layout names understood by this method are:

Parameters
graphUndocumented
layoutthe layout to use. This can be one of the registered layout names or a callable which returns either a Layout object or a list of lists containing the coordinates. If None, uses the value of the plotting.layout configuration key.
*argsUndocumented
**kwdsUndocumented
Returns
a Layout object.
def _layout_auto(graph, *args, **kwds): (source)

Chooses and runs a suitable layout function based on simple topological properties of the graph.

This function tries to choose an appropriate layout function for the graph using the following rules:

  1. If the graph has an attribute called layout, it will be used. It may either be a Layout instance, a list of coordinate pairs, the name of a layout function, or a callable function which generates the layout when called with the graph as a parameter.
  2. Otherwise, if the graph has vertex attributes called x and y, these will be used as coordinates in the layout. When a 3D layout is requested (by setting dim to 3), a vertex attribute named z will also be needed.
  3. Otherwise, if the graph is connected and has at most 100 vertices, the Kamada-Kawai layout will be used (see GraphBase.layout_kamada_kawai()).
  4. Otherwise, if the graph has at most 1000 vertices, the Fruchterman-Reingold layout will be used (see GraphBase.layout_fruchterman_reingold()).
  5. If everything else above failed, the DrL layout algorithm will be used (see GraphBase.layout_drl()).

All the arguments of this function except dim are passed on to the chosen layout function (in case we have to call some layout function).

Parameters
graphUndocumented
*argsUndocumented
dimspecifies whether we would like to obtain a 2D or a 3D layout.
Returns
a Layout object.
def _layout_method_wrapper(func): (source)

Wraps an existing layout method to ensure that it returns a Layout instead of a list of lists.

Parameters
functhe method to wrap. Must be a method of the Graph object.
Returns
a new method
def _layout_sugiyama(graph, layers=None, weights=None, hgap=1, vgap=1, maxiter=100): (source)

Places the vertices using a layered Sugiyama layout.

This is a layered layout that is most suitable for directed acyclic graphs, although it works on undirected or cyclic graphs as well.

Each vertex is assigned to a layer and each layer is placed on a horizontal line. Vertices within the same layer are then permuted using the barycenter heuristic that tries to minimize edge crossings.

Dummy vertices will be added on edges that span more than one layer. The returned layout therefore contains more rows than the number of nodes in the original graph; the extra rows correspond to the dummy vertices.

References:

  • K Sugiyama, S Tagawa, M Toda: Methods for visual understanding of hierarchical system structures. IEEE Systems, Man and Cybernetics 11(2):109-125, 1981.
  • P Eades, X Lin and WF Smyth: A fast effective heuristic for the feedback arc set problem. Information Processing Letters 47:319-323, 1993.
Parameters
graphUndocumented
layersa vector specifying a non-negative integer layer index for each vertex, or the name of a numeric vertex attribute that contains the layer indices. If None, a layering will be determined automatically. For undirected graphs, a spanning tree will be extracted and vertices will be assigned to layers using a breadth first search from the node with the largest degree. For directed graphs, cycles are broken by reversing the direction of edges in an approximate feedback arc set using the heuristic of Eades, Lin and Smyth, and then using longest path layering to place the vertices in layers.
weightsedge weights to be used. Can be a sequence or iterable or even an edge attribute name.
hgapminimum horizontal gap between vertices in the same layer.
vgapvertical gap between layers. The layer index will be multiplied by vgap to obtain the Y coordinate.
maxitermaximum number of iterations to take in the crossing reduction step. Increase this if you feel that you are getting too many edge crossings.
Returns
the calculated layout and an additional list of matrices where the i-th matrix contains the control points of edge i in the original graph (or an empty matrix if no control points are needed on the edge)
_layout_mapping: dict[str, str] = (source)

Undocumented