planar_layout#

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

Position nodes without edge intersections.

Parameters:
GNetworkX graph or list of nodes

A position will be assigned to every node in G. If G is of type nx.PlanarEmbedding, the positions are selected accordingly.

scalenumber (default: 1)

Scale factor for positions.

centerarray-like or None

Coordinate pair around which to center the layout.

dimint

Dimension of layout.

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:
NetworkXException

If G is not planar

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.planar_layout(G)
>>> # supress the returned dict and store on the graph directly
>>> _ = nx.planar_layout(G, store_pos_as="pos")
>>> nx.get_node_attributes(G, "pos")
{0: array([-0.77777778, -0.33333333]), 1: array([ 1.        , -0.33333333]), 2: array([0.11111111, 0.55555556]), 3: array([-0.33333333,  0.11111111])}