circular_layout#

circular_layout(G, scale=1, center=None, dim=2, store_pos_as=None)[source]#

Position nodes on a circle.

Parameters:
GNetworkX graph or list of nodes

A position will be assigned to every node in G.

scalenumber (default: 1)

Scale factor for positions.

centerarray-like or None

Coordinate pair around which to center the layout.

dimint

Dimension of layout. If dim>2, the remaining dimensions are set to zero in the returned positions. If dim<2, a ValueError is raised.

store_pos_asstr, default None

If non-None, the position of each node will be stored on the graph as an attribute with this string as its name, which can be accessed with G.nodes[...][store_pos_as]. The function still returns the dictionary.

Returns:
posdict

A dictionary of positions keyed by node

Raises:
ValueError

If dim < 2

Notes

This algorithm currently only works in two dimensions and does not try to minimize edge crossings.

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.circular_layout(G)
>>> # supress the returned dict and store on the graph directly
>>> _ = nx.circular_layout(G, store_pos_as="pos")
>>> nx.get_node_attributes(G, "pos")
{0: array([9.99999986e-01, 2.18556937e-08]), 1: array([-3.57647606e-08,  1.00000000e+00]), 2: array([-9.9999997e-01, -6.5567081e-08]), 3: array([ 1.98715071e-08, -9.99999956e-01])}