kamada_kawai_layout#

kamada_kawai_layout(G, dist=None, pos=None, weight='weight', scale=1, center=None, dim=2)[source]#

Position nodes using Kamada-Kawai path-length cost-function.

Parameters:
GNetworkX graph or list of nodes

A position will be assigned to every node in G.

distdict (default=None)

A two-level dictionary of optimal distances between nodes, indexed by source and destination node. If None, the distance is computed using shortest_path_length().

posdict or None optional (default=None)

Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use circular_layout() for dim >= 2 and a linear layout for dim == 1.

weightstring or None optional (default=’weight’)

The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.

scalenumber (default: 1)

Scale factor for positions.

centerarray-like or None

Coordinate pair around which to center the layout.

dimint

Dimension of layout.

Returns:
posdict

A dictionary of positions keyed by node

Examples

>>> G = nx.path_graph(4)
>>> pos = nx.kamada_kawai_layout(G)