Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / examples / graph / plot_erdos_renyi.py @ 5cef0f13

History | View | Annotate | Download (931 Bytes)

1
# -*- coding: utf-8 -*-
2
#!/usr/bin/env python
3
"""
4
===========
5
Erdos Renyi
6
===========
7

8
Create an G{n,m} random graph with n nodes and m edges
9
and report some properties.
10

11
This graph is sometimes called the Erdős-Rényi graph
12
but is different from G{n,p} or binomial_graph which is also
13
sometimes called the Erdős-Rényi graph.
14
"""
15
# Author: Aric Hagberg (hagberg@lanl.gov)
16

    
17
#    Copyright (C) 2004-2019 by
18
#    Aric Hagberg <hagberg@lanl.gov>
19
#    Dan Schult <dschult@colgate.edu>
20
#    Pieter Swart <swart@lanl.gov>
21
#    All rights reserved.
22
#    BSD license.
23

    
24
import matplotlib.pyplot as plt
25
from networkx import nx
26

    
27
n = 10  # 10 nodes
28
m = 20  # 20 edges
29

    
30
G = nx.gnm_random_graph(n, m)
31

    
32
# some properties
33
print("node degree clustering")
34
for v in nx.nodes(G):
35
    print('%s %d %f' % (v, nx.degree(G, v), nx.clustering(G, v)))
36

    
37
# print the adjacency list
38
for line in nx.generate_adjlist(G):
39
    print(line)
40

    
41
nx.draw(G)
42
plt.show()