fruchterman_reingold_layout¶
-
fruchterman_reingold_layout
(G, dim=2, k=None, pos=None, fixed=None, iterations=50, weight='weight', scale=1.0, center=None)[source]¶ Position nodes using Fruchterman-Reingold force-directed algorithm.
Parameters: - G (NetworkX graph) –
- dim (int) – Dimension of layout
- k (float (default=None)) – Optimal distance between nodes. If None the distance is set to 1/sqrt(n) where n is the number of nodes. Increase this value to move nodes farther apart.
- pos (dict or None optional (default=None)) – Initial positions for nodes as a dictionary with node as keys and values as a list or tuple. If None, then use random initial positions.
- fixed (list or None optional (default=None)) – Nodes to keep fixed at initial position. If any nodes are fixed, the scale and center features are not used.
- iterations (int optional (default=50)) – Number of iterations of spring-force relaxation
- weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the effective spring constant. If None, edge weights are 1.
- scale (float (default=1.0)) – Scale factor for positions. The nodes are positioned in a box of size \(scale\) in each dim centered at \(center\).
- center (array-like (default scale/2 in each dim)) – Coordinate around which to center the layout.
Returns: A dictionary of positions keyed by node
Return type: Examples
>>> G=nx.path_graph(4) >>> pos=nx.spring_layout(G)
# this function has two names: # spring_layout and fruchterman_reingold_layout >>> pos=nx.fruchterman_reingold_layout(G)