lgl_layout#
- graph_tool.draw.lgl_layout(g, root=None, pos=None, dim=2, K=1.0, cutoff=None, maxit=150, max_step=None, coolexp=1.5)[git][source]#
Calculate a layout of the graph with the Large Graph Layout (LGL) algorithm.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- root
intorVertex(optional, default:None) Vertex from which the layout grows. If not given, a random vertex is chosen. The components that do not contain it grow from a random vertex.
- pos
VertexPropertyMap(optional, default:None) If provided, the positions will be stored in this property map.
- dim
int(optional, default:2) Number of dimensions, either 2 or 3.
- K
float(optional, default:1.) Natural edge length.
- cutoff
float(optional, default:None) Distance beyond which vertices do not repel. If not given,
2 * Kis used.- maxit
int(optional, default:150) Number of iterations after the addition of every shell.
- max_step
float(optional, default:None) Largest move of a vertex in the first iteration after the addition of every shell. If not given,
Kis used.- coolexp
float(optional, default:1.5) Exponent of the cooling schedule.
- g
- Returns:
- pos
VertexPropertyMap The vertex positions.
- pos
See also
fruchterman_reingold_layoutFruchterman-Reingold spring-block layout
drl_layoutDrL force-directed layout
sfdp_layoutMultilevel force-directed layout
Notes
The LGL algorithm [adai-lgl-2004] grows the layout from a root vertex, one breadth-first shell at a time: every vertex of a new shell is placed at distance \(K\) from its parent in the breadth-first search tree, in a random direction that points away from the parent of the parent (a uniformly random direction, reversed if it has a negative projection on the vector from the grandparent to the parent), and the vertices placed so far are then relaxed with
maxititerations of the forces of Fruchterman and Reingold [fruchterman-graph-1991], the attraction \(d^2/K\) between neighbors and the repulsion \(K^2/d\) between vertices closer thancutoff, i.e. the total force\[\boldsymbol F_v = \sum_{u\,:\,0 < d_{uv} < R}K^2\frac{\boldsymbol x_v - \boldsymbol x_u}{d_{uv}^2} - \sum_{u\in\partial v}\frac{d_{uv} (\boldsymbol x_v - \boldsymbol x_u)}{K},\]where \(d_{uv} = |\boldsymbol x_v - \boldsymbol x_u|\), \(R\) is
cutoffand both sums run over the placed vertices. In iteration \(i = 0, \dots, n - 1\), all placed vertices move at once by \(\boldsymbol F_v\min(1, t_i/|\boldsymbol F_v|)\), i.e. by at most the temperature \(t_i = t_0(1 - i/n)^c\), where \(t_0\) ismax_step, \(n\) ismaxit, and \(c\) iscoolexp. The root starts at the origin. The repulsion is computed with a grid of cells of sidecutoff, so that only vertices in neighboring cells interact. Every iteration takes time \(O(V + E)\) for vertices that are spread evenly, and the whole layout \(O(Dn(V + E))\), where \(D\) is the eccentricity of the root. The connected components are laid out separately and placed side by side. The root vertices are chosen with NumPy’s random number generator, and the directions with graph-tool’s.Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
References
[adai-lgl-2004]Alex T. Adai, Shailesh V. Date, Shannon Wieland and Edward M. Marcotte, “LGL: Creating a map of protein function with an algorithm for visualizing very large biological networks”, Journal of Molecular Biology 340, 179-190 (2004), DOI: 10.1016/j.jmb.2004.04.047 [sci-hub, @tor]
[fruchterman-graph-1991]Thomas M. J. Fruchterman and Edward M. Reingold, “Graph drawing by force-directed placement”, Software: Practice and Experience 21, 1129-1164 (1991), DOI: 10.1002/spe.4380211102 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["power"] >>> pos = gt.lgl_layout(g) >>> gt.graph_draw(g, pos=pos, output="power-lgl.png") <...>
LGL layout of the power grid of the western United States.#