Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.drawing.layout.bipartite_layout

bipartite_layout(G, nodes, align='vertical', scale=1, center=None, aspect_ratio=1.3333333333333333)[source]

Position nodes in two straight lines.

Parameters
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.

  • nodes (list or container) – Nodes in one node set of the bipartite graph. This set will be placed on left or top.

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

  • aspect_ratio (number (default=4/3):) – The ratio of the width to the height of the layout.

Returns

pos – A dictionary of positions keyed by node.

Return type

dict

Examples

>>> G = nx.bipartite.gnmk_random_graph(3, 5, 10, seed=123)
>>> top = nx.bipartite.sets(G)[0]
>>> pos = nx.bipartite_layout(G, top)

Notes

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