networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturns
hexagonal_lattice_graph(m, n, periodic=False, with_positions=True, create_using=None)

The hexagonal lattice graph is a graph whose nodes and edges are the :None:None:`hexagonal tiling` of the plane.

The returned graph will have m rows and n columns of hexagons. :None:None:`Odd numbered columns` are shifted up relative to even numbered columns.

Positions of nodes are computed by default or :None:None:`with_positions is True`. Node positions creating the standard embedding in the plane with sidelength 1 and are stored in the node attribute 'pos'. :None:None:`pos = nx.get_node_attributes(G, 'pos')` creates a dict ready for drawing.

            <Unimplemented 'target' '.. _hexagonal tiling: https://en.wikipedia.org/wiki/Hexagonal_tiling'>
           
            <Unimplemented 'target' '.. _Odd numbered columns: http://www-cs-students.stanford.edu/~amitp/game-programming/grids/'>
           

Parameters

m : int

The number of rows of hexagons in the lattice.

n : int

The number of columns of hexagons in the lattice.

periodic : bool

Whether to make a periodic grid by joining the boundary vertices. For this to work n must be odd and both :None:None:`n > 1` and :None:None:`m > 1`. The periodic connections create another row and column of hexagons so these graphs have fewer nodes as boundary nodes are identified.

with_positions : bool (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_using : NetworkX 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.

Returns an m by n hexagonal lattice graph.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/generators/lattice.py#271
type: <class 'function'>
Commit: