grid_layout#
- graph_tool.draw.grid_layout(g, shape=None, dim=2, order=None, pos=None)[git][source]#
Place the vertices on a regular grid.
- Parameters:
- g
Graph Graph to be used.
- shapeiterable of
int(optional, default:None) Number of vertices along each of the first
dim - 1axes (the last one extends as needed). If not given, \(\lceil V^{1/d}\rceil\) vertices are placed along every axis, where \(d\) isdim.- dim
int(optional, default:2) Number of dimensions.
- orderiterable of
int(optional, default:None) The vertices in the order in which they fill the grid. If not given, the order of the vertex indices is used.
- pos
VertexPropertyMap(optional, default:None) If provided, the positions will be stored in this property map.
- g
- Returns:
- pos
VertexPropertyMap The vertex positions.
- pos
See also
circle_layoutVertices on a circle
spiral_layoutVertices along a spiral
random_layoutRandom layout
Notes
The vertices fill the grid with unit spacing, row by row (and layer by layer in three dimensions), starting at the origin: in \(d\) dimensions (given by
dim), with the numbers of vertices \(m_0, \dots, m_{d-2}\) along the first \(d - 1\) axes, given byshape(or all equal to the smallest integer \(m\) with \(m^d \ge n\) for \(n\) vertices), the \(k\)-th vertex in the order, with \(k = 0, \dots, n - 1\), has the coordinates\[x_{k,i} = \left\lfloor\frac{k}{\prod_{j<i}m_j}\right\rfloor \bmod m_i, \qquad x_{k,d-1} = \left\lfloor\frac{k}{\prod_{j<d-1} m_j}\right\rfloor,\]for \(i < d - 1\). The edges are ignored.
Examples
>>> g = gt.collection.data["karate"] >>> pos = gt.grid_layout(g) >>> print(pos[0].a, pos[5].a, pos[6].a) [0. 0.] [5. 0.] [0. 1.] >>> gt.graph_draw(g, pos=pos, output="grid-layout-karate.pdf") <...>
Grid layout of the karate club network, with the vertices placed in rows of six, in the order of their indices, starting at the top left corner.#