networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
random_geometric_graph(n, radius, dim=2, pos=None, p=2, seed=None)

The random geometric graph model places n nodes uniformly at random in the unit cube. Two nodes are joined by an edge if the distance between the nodes is at most radius .

Edges are determined using a KDTree when SciPy is available. This reduces the time complexity from $O(n^2)$ to $O(n)$.

Notes

This uses a k-d tree to build the graph.

The :None:None:`pos` keyword argument can be used to specify node positions so you can create an arbitrary distribution and domain for positions.

For example, to use a 2D Gaussian distribution of node positions with mean (0, 0) and standard deviation 2:

>>> import random
>>> n = 20
>>> pos = {i: (random.gauss(0, 2), random.gauss(0, 2)) for i in range(n)}
>>> G = nx.random_geometric_graph(n, 0.2, pos=pos)

Parameters

n : int or iterable

Number of nodes or iterable of nodes

radius: float :

Distance threshold value

dim : int, optional

Dimension of graph

pos : dict, optional

A dictionary keyed by node with node positions as values.

p : float, optional

Which Minkowski distance metric to use. p has to meet the condition 1 <= p <= infinity .

If this argument is not specified, the $L^2$ metric (the Euclidean distance metric), p = 2 is used. This should not be confused with the p of an Erdős-Rényi random graph, which represents probability.

seed : integer, random_state, or None (default)

Indicator of random number generation state. See Randomness<randomness> .

Returns

Graph

A random geometric graph, undirected and without self-loops. Each node has a node attribute 'pos' that stores the position of that node in Euclidean space as provided by the pos keyword argument or, if pos was not provided, as generated by this function.

Returns a random geometric graph in the unit cube of dimensions :None:None:`dim`.

Examples

>>> G = nx.random_geometric_graph(20, 0.1)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.generators.geometric.random_geometric_graph

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/generators/geometric.py#109
type: <class 'function'>
Commit: