align_layout#
- graph_tool.draw.align_layout(g, pos)[git][source]#
Align a layout with the coordinate axes.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- pos
VertexPropertyMap Vector vertex property map with the positions, of any dimension.
- g
- Returns:
- pos
VertexPropertyMap A new vector vertex property map with the aligned positions.
- pos
See also
pack_layoutPacking of the layouts of the components
Notes
The layout is centered at the origin, and rotated so that the principal axes of the tensor \(\sum_{(i,j)\in E}(\boldsymbol{x}_i - \boldsymbol{x}_j)(\boldsymbol{x}_i - \boldsymbol{x}_j)^T\) of the edge vectors are along the coordinate axes. (If all edges have zero length, the principal axes of the vertex positions are used.) The axes are sorted in decreasing order of the extent of the layout along them, so that the widest axis is horizontal, and every axis is oriented so that the third moment of the coordinates along it is nonnegative. The result does not depend on rotations, translations, or reflections of the input layout, which is useful for comparing the results of force-directed layouts. It runs in time \(O(Vd^2 + Ed^2 + d^3)\) in \(d\) dimensions.
Examples
>>> g = gt.collection.data["lesmis"] >>> pos0 = gt.sfdp_layout(g) >>> pos = gt.align_layout(g, pos0) >>> X = pos.get_2d_array([0, 1]) >>> print(np.allclose(X.mean(axis=1), 0), np.ptp(X[0]) >= np.ptp(X[1])) True True
The two layouts are compared in the figures below, which are obtained with
>>> gt.graph_draw(g, pos=pos0, output="align-layout-input.pdf") <...> >>> gt.graph_draw(g, pos=pos, output="align-layout-aligned.pdf") <...>
Layout of the network of co-appearances of characters in Les Misérables, obtained with
sfdp_layout().#
The same layout after
align_layout(), with the widest axis horizontal.#