Warning

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

random_layout

random_layout(G, dim=2, center=None)[source]

Position nodes uniformly at random in the unit square.

For every node, a position is generated by choosing each of dim coordinates uniformly at random on the interval [0.0, 1.0).

NumPy (http://scipy.org) is required for this function.

Parameters:
  • G (NetworkX graph or list of nodes) – A position will be assigned to every node in G.
  • dim (int) – Dimension of layout.
  • center (array-like or None) – Coordinate pair around which to center the layout.
Returns:

pos – A dictionary of positions keyed by node

Return type:

dict

Examples

>>> G = nx.lollipop_graph(4, 3)
>>> pos = nx.random_layout(G)