Note
Click here to download the full example code
Erdos Renyi¶
Create an G{n,m} random graph with n nodes and m edges and report some properties.
This graph is sometimes called the Erdős-Rényi graph but is different from G{n,p} or binomial_graph which is also sometimes called the Erdős-Rényi graph.

Out:
node degree clustering
0 2 0.000000
1 7 0.380952
2 5 0.700000
3 5 0.500000
4 3 0.666667
5 3 1.000000
6 5 0.500000
7 4 0.166667
8 4 0.833333
9 2 0.000000
0 1 9
1 4 5 2 3 8 6
2 5 3 6 8
3 8 4 7
4 7
5 6
6 8 7
7 9
8
9
# Author: Aric Hagberg (hagberg@lanl.gov)
# Copyright (C) 2004-2019 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Pieter Swart <swart@lanl.gov>
# All rights reserved.
# BSD license.
import matplotlib.pyplot as plt
from networkx import nx
n = 10 # 10 nodes
m = 20 # 20 edges
G = nx.gnm_random_graph(n, m)
# some properties
print("node degree clustering")
for v in nx.nodes(G):
print('%s %d %f' % (v, nx.degree(G, v), nx.clustering(G, v)))
# print the adjacency list
for line in nx.generate_adjlist(G):
print(line)
nx.draw(G)
plt.show()
Total running time of the script: ( 0 minutes 0.019 seconds)