networkx.generators.lattice.triangular_lattice_graph¶
-
triangular_lattice_graph
(m, n, periodic=False, with_positions=True, create_using=None)[source]¶ Returns the \(m\) by \(n\) triangular lattice graph.
The triangular lattice graph is a two-dimensional grid graph in which each square unit has a diagonal edge (each grid unit has a chord).
The returned graph has \(m\) rows and \(n\) columns of triangles. Rows and columns include both triangles pointing up and down. Rows form a strip of constant height. Columns form a series of diamond shapes, staggered with the columns on either side. Another way to state the size is that the nodes form a grid of
m+1
rows and(n + 1) // 2
columns. The odd row nodes are shifted horizontally relative to the even rows.Directed graph types have edges pointed up or right.
Positions of nodes are computed by default or
with_positions is True
. The position of each node (embedded in a euclidean plane) is stored in the graph using equilateral triangles with sidelength 1. The height between rows of nodes is thus \(\sqrt(3)/2\). Nodes lie in the first quadrant with the node \((0, 0)\) at the origin.Parameters: - m (int) – The number of rows in the lattice.
- n (int) – The number of columns in the lattice.
- periodic (bool (default: False)) – If True, join the boundary vertices of the grid using periodic
boundary conditions. The join between boundaries is the final row
and column of triangles. This means there is one row and one column
fewer nodes for the periodic lattice. Periodic lattices require
m >= 3
,n >= 5
and are allowed but misaligned ifm
orn
are odd - with_positions (bool (default: True)) – Store the coordinates of each node in the graph node attribute ‘pos’. The coordinates provide a lattice with equilateral triangles. Periodic positions shift the nodes vertically in a nonlinear way so the edges don’t overlap so much.
- create_using (NetworkX graph) – If specified, this must be an instance of a NetworkX graph class. It will be cleared of nodes and edges and filled with the new graph. Usually used to set the type of the graph.
Returns: The m by n triangular lattice graph.
Return type: NetworkX graph