networkx.drawing.layout.spectral_layout

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

Position nodes using the eigenvectors of the graph Laplacian.

Using the unnormalized Laplacion, the layout shows possible clusters of nodes which are an approximation of the ratio cut. If dim is the number of dimensions then the positions are the entries of the dim eigenvectors corresponding to the ascending eigenvalues starting from the second one.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • 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 (number (default: 1)) – Scale factor for positions.
  • center (array-like or None) – Coordinate pair around which to center the layout.
  • dim (int) – Dimension of layout.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

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

Notes

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).