Previous topic


Next topic



spring_layout(G, dim=2, pos=None, fixed=None, iterations=50, weight='weight', scale=1)

Position nodes using Fruchterman-Reingold force-directed algorithm.

Parameters :

G : NetworkX graph

dim : int

Dimension of layout

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 nuse random initial positions.

fixed : list or None optional (default=None)

Nodes to keep fixed at initial position.

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 edge weight. If None, then all edge weights are 1.

scale : float

Scale factor for positions

Returns :

dict : :

A dictionary of positions keyed by node


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

# The same using longer function name >>> pos=nx.fruchterman_reingold_layout(G)