Skip to main content
`Ctrl`+`K`

# multipartite_layout

multipartite_layout(G, subset_key='subset', align='vertical', scale=1, center=None)

  Position nodes in layers of straight lines.

  Parameters:
    G NetworkX graph or list of nodes

      A position will be assigned to every node in G.

    subset_key string 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.

    align string (default=’vertical’)

      The alignment of nodes. Vertical or horizontal.

    scale number (default: 1)

      Scale factor for positions.

    center array-like or None

      Coordinate pair around which to center the layout.

  Returns:
    pos dict

      A dictionary of positions keyed by node.

  Notes

  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.

  Examples

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