NetworkX

Previous topic

networkx.drawing.layout.shell_layout

Next topic

networkx.drawing.layout.spectral_layout

networkx.drawing.layout.spring_layout

networkx.drawing.layout.spring_layout(G, dim=2, pos=None, fixed=None, iterations=50, weighted=True, scale=1)

Position nodes using Fruchterman-Reingold force-directed algorithm.

Parameters :

G : NetworkX graph

dim : int

Dimension of layout

pos : dict

Initial positions for nodes as a dictionary with node as keys and values as a list or tuple.

fixed : list

Nodes to keep fixed at initial position.

iterations : int

Number of iterations of spring-force relaxation

weighted : boolean

If True, use edge weights in layout

scale : float

Scale factor for positions

Returns :

dict : :

A dictionary of positions keyed by node

Examples

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

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