pack_layout#
- graph_tool.draw.pack_layout(g, pos, groups=None)[git][source]#
Pack the layouts of the connected components (or of groups of vertices) side by side.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- pos
VertexPropertyMap Vector vertex property map with the positions.
- groups
VertexPropertyMap(optional, default:None) Scalar vertex property map with the groups of vertices whose layouts are packed. If not given, the connected components are used.
- g
- Returns:
- pos
VertexPropertyMap A new vector vertex property map with the packed positions.
- pos
See also
align_layoutAlignment of a layout with the coordinate axes
graph_tool.structure.label_componentsConnected components of the graph
Notes
The layout of every component (or group) is translated, without rotations or rescaling, so that the bounding boxes of the components are placed in rows, left to right and in decreasing order of the number of vertices (and in increasing order of their labels, for equal numbers). With the mean edge length \(\ell\), the width \(w_c\) and height \(h_c\) of every bounding box are taken to be at least \(\ell\) (e.g. for isolated vertices), the boxes are separated horizontally and vertically by the gap \(\gamma = 0.2\tilde w + \ell\), where \(\tilde w\) is the median width, and a new row is started when a box would extend beyond the width
\[W = \max\left(\sqrt{\textstyle\sum_c(w_c + \gamma)(h_c + \gamma)}, w_1 + \gamma\right),\]where \(w_1\) is the width of the first box, so that the rows have approximately equal widths, and the packing is roughly square. Every row is as high as its highest box. (In one dimension, all components are in a single row.) This is the packing used by the layout functions of this module for disconnected graphs (with \(\ell = 1\)). It runs in time \(O(V + E + C\log C)\) for \(C\) components.
Examples
The Fruchterman-Reingold layout of a disconnected graph spreads its components, whose layouts can be packed side by side as follows:
>>> g = gt.collection.data["netscience"] >>> pos = gt.fruchterman_reingold_layout(g, n_iter=200) >>> pos = gt.pack_layout(g, pos) >>> gt.graph_draw(g, pos=pos, output="netscience-packed.pdf") <...>
Fruchterman-Reingold layout of the network of coauthorships in network science, with the connected components packed side by side.#