diff options
Diffstat (limited to 'examples/graph/plot_expected_degree_sequence.py')
| -rw-r--r-- | examples/graph/plot_expected_degree_sequence.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/graph/plot_expected_degree_sequence.py b/examples/graph/plot_expected_degree_sequence.py new file mode 100644 index 00000000..78b5bf90 --- /dev/null +++ b/examples/graph/plot_expected_degree_sequence.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +""" +======================== +Expected Degree Sequence +======================== + +Random graph from given degree sequence. +""" +# Author: Aric Hagberg (hagberg@lanl.gov) + +# Copyright (C) 2006-2019 by +# Aric Hagberg <hagberg@lanl.gov> +# Dan Schult <dschult@colgate.edu> +# Pieter Swart <swart@lanl.gov> +# All rights reserved. +# BSD license. + +import networkx as nx +from networkx.generators.degree_seq import expected_degree_graph + +# make a random graph of 500 nodes with expected degrees of 50 +n = 500 # n nodes +p = 0.1 +w = [p * n for i in range(n)] # w = p*n for all nodes +G = expected_degree_graph(w) # configuration model +print("Degree histogram") +print("degree (#nodes) ****") +dh = nx.degree_histogram(G) +low = min(nx.degree(G)) +for i in range(low, len(dh)): + bar = ''.join(dh[i] * ['*']) + print("%2s (%2s) %s" % (i, dh[i], bar)) |
