hexagonal_lattice_graph#
- hexagonal_lattice_graph(m, n, periodic=False, with_positions=True, create_using=None)[source]#
Returns an m by n hexagonal lattice graph.
The hexagonal lattice graph is a graph whose nodes and edges are the hexagonal tiling of the plane.
The returned graph will have m rows and n columns of hexagons. Odd numbered columns are shifted up relative to even numbered columns.
Positions of nodes are computed by default or with_positions is True. Node positions creating the standard embedding in the plane with sidelength 1 and are stored in the node attribute ‘pos’. pos = nx.get_node_attributes(G, ‘pos’) creates a dict ready for drawing.
- Parameters:
- mint
The number of rows of hexagons in the lattice.
- nint
The number of columns of hexagons in the lattice.
- periodicbool
Whether to make a periodic grid by joining the boundary vertices. For this to work n must be even and both n > 1 and m > 1. The periodic connections create another row and column of hexagons so these graphs have fewer nodes as boundary nodes are identified.
- with_positionsbool (default: True)
Store the coordinates of each node in the graph node attribute ‘pos’. The coordinates provide a lattice with vertical columns of hexagons offset to interleave and cover the plane. Periodic positions shift the nodes vertically in a nonlinear way so the edges don’t overlap so much.
- create_usingNetworkX graph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated. If graph is directed, edges will point up or right.
- Returns:
- NetworkX graph
The m by n hexagonal lattice graph.
See also
grid_2d_graph,triangular_lattice_graphOther 2D lattice graphs
grid_graph,hypercube_graphN-dimensional lattice graphs