random_layout

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

Position nodes uniformly at random.

For every node, a position is generated by choosing each of dim coordinates uniformly at random on the default interval [0.0, 1.0), or on an interval of length \(scale\) centered at \(center\).

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.
  • scale (float (default 1)) – Scale factor for positions
  • center (array-like (default scale*0.5 in each dim)) – Coordinate 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)