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 4 0.666667
1 3 1.000000
2 6 0.400000
3 2 1.000000
4 5 0.300000
5 2 0.000000
6 3 0.666667
7 4 0.666667
8 8 0.357143
9 3 1.000000
#/build/python-networkx-2.2/examples/graph/plot_erdos_renyi.py
# GMT Thu Apr 8 00:27:38 2021
#
0 8 9 2 6
1 8 2 7
2 5 7 8 9
3 8 4
4 8 5 6 7
5
6 8
7 8
8 9
9
# Author: Aric Hagberg (hagberg@lanl.gov)
# Copyright (C) 2004-2018 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Pieter Swart <swart@lanl.gov>
# All rights reserved.
# BSD license.
import sys
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 to terminal
try:
nx.write_adjlist(G, sys.stdout)
except TypeError: # Python 3.x
nx.write_adjlist(G, sys.stdout.buffer)
nx.draw(G)
plt.show()
Total running time of the script: ( 0 minutes 0.035 seconds)