Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (959 Bytes)

1
#!/usr/bin/env python
2
"""
3
===============
4
Degree Sequence
5
===============
6

7
Random graph from given degree sequence.
8
"""
9
# Author: Aric Hagberg (hagberg@lanl.gov)
10
# Date: 2004-11-03 08:11:09 -0700 (Wed, 03 Nov 2004)
11
# Revision: 503
12

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

    
20
import matplotlib.pyplot as plt
21
from networkx import nx
22

    
23
z = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1]
24
print(nx.is_graphical(z))
25

    
26
print("Configuration model")
27
G = nx.configuration_model(z)  # configuration model
28
degree_sequence = [d for n, d in G.degree()]  # degree sequence
29
print("Degree sequence %s" % degree_sequence)
30
print("Degree histogram")
31
hist = {}
32
for d in degree_sequence:
33
    if d in hist:
34
        hist[d] += 1
35
    else:
36
        hist[d] = 1
37
print("degree #nodes")
38
for d in hist:
39
    print('%d %d' % (d, hist[d]))
40

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