kamada_kawai_layout#
- kamada_kawai_layout(G, dist=None, pos=None, weight='weight', scale=1, center=None, dim=2, store_pos_as=None)[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.
- 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
Examples
>>> G = nx.path_graph(4) >>> pos = nx.kamada_kawai_layout(G) >>> # supress the returned dict and store on the graph directly >>> _ = nx.kamada_kawai_layout(G, store_pos_as="pos") >>> nx.get_node_attributes(G, "pos") {0: array([0.99996577, 0.99366857]), 1: array([0.32913544, 0.33543827]), 2: array([-0.33544334, -0.32910684]), 3: array([-0.99365787, -1. ])}