Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (815 Bytes)

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

7
Random graph from given degree sequence.
8
"""
9
# Author: Aric Hagberg (hagberg@lanl.gov)
10

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

    
18
import networkx as nx
19
from networkx.generators.degree_seq import expected_degree_graph
20

    
21
# make a random graph of 500 nodes with expected degrees of 50
22
n = 500  # n nodes
23
p = 0.1
24
w = [p * n for i in range(n)]  # w = p*n for all nodes
25
G = expected_degree_graph(w)  # configuration model
26
print("Degree histogram")
27
print("degree (#nodes) ****")
28
dh = nx.degree_histogram(G)
29
for i, d in enumerate(dh):
30
    print("%2s (%2s) %s" % (i, d, '*'*d))