multipartite_layout(G, subset_key='subset', align='vertical', scale=1, center=None)[source]#

Position nodes in layers of straight lines.

GNetworkX graph or list of nodes

A position will be assigned to every node in G.

subset_keystring or dict (default=’subset’)

If a string, the key of node data in G that holds the node subset. If a dict, keyed by layer number to the nodes in that layer/subset.

alignstring (default=’vertical’)

The alignment of nodes. Vertical or horizontal.

scalenumber (default: 1)

Scale factor for positions.

centerarray-like or None

Coordinate pair around which to center the layout.


A dictionary of positions keyed by node.


This algorithm currently only works in two dimensions and does not try to minimize edge crossings.

Network does not need to be a complete multipartite graph. As long as nodes have subset_key data, they will be placed in the corresponding layers.


>>> G = nx.complete_multipartite_graph(28, 16, 10)
>>> pos = nx.multipartite_layout(G)

or use a dict to provide the layers of the layout

>>> G = nx.Graph([(0, 1), (1, 2), (1, 3), (3, 4)])
>>> layers = {"a": [0], "b": [1], "c": [2, 3], "d": [4]}
>>> pos = nx.multipartite_layout(G, subset_key=layers)