spectral_layout(G, dim=2, weight='weight', scale=1.0, center=None)[source]

Position nodes using the eigenvectors of the graph Laplacian.

  • G (NetworkX graph or list of nodes) –
  • dim (int) – Dimension of layout
  • 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 optional (default 1)) – Scale factor for positions, i.e. nodes placed in a box with side [0, scale] or centered on \(center\) if provided.
  • center (array-like (default scale/2 in each dim)) – Coordinate around which to center the layout.

A dictionary of positions keyed by node

Return type:



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


Directed graphs will be considered as undirected graphs when positioning the nodes.

For larger graphs (>500 nodes) this will use the SciPy sparse eigenvalue solver (ARPACK).