This documents the development version of NetworkX. Documentation for the current release can be found here.
hexagonal_lattice_graph(m, n, periodic=False, with_positions=True, create_using=None)¶
nhexagonal 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
ncolumns 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.
The number of rows of hexagons in the lattice.
The number of columns of hexagons in the lattice.
Whether to make a periodic grid by joining the boundary vertices. For this to work
nmust be odd and both
n > 1and
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.
- NetworkX graph
The m by n hexagonal lattice graph.