diff options
| author | Jarrod Millman <jarrod.millman@gmail.com> | 2017-07-21 08:50:40 -0700 |
|---|---|---|
| committer | Dan Schult <dschult@colgate.edu> | 2017-07-21 11:50:40 -0400 |
| commit | 1e6df4c105fa7a1e442da72ddb009bb253dc7d4e (patch) | |
| tree | d728526ccca673a762f90f174223cb558c86e02d /examples/graph/plot_degree_sequence.py | |
| parent | 7be0d8f33b46d37264ae181cb2a9fadb310fe687 (diff) | |
| download | networkx-1e6df4c105fa7a1e442da72ddb009bb253dc7d4e.tar.gz | |
Refactor examples (#2527)
* Fix unix_email and plot more examples
* Fix doctest
* Fix more examples
* Fix AntiGraph.degree generator error in examples
* Style/consistency changes and plot more examples
Diffstat (limited to 'examples/graph/plot_degree_sequence.py')
| -rw-r--r-- | examples/graph/plot_degree_sequence.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/graph/plot_degree_sequence.py b/examples/graph/plot_degree_sequence.py new file mode 100644 index 00000000..6ba7a644 --- /dev/null +++ b/examples/graph/plot_degree_sequence.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +""" +=============== +Degree Sequence +=============== + +Random graph from given degree sequence. +""" +# Author: Aric Hagberg (hagberg@lanl.gov) +# Date: 2004-11-03 08:11:09 -0700 (Wed, 03 Nov 2004) +# Revision: 503 + +# Copyright (C) 2004-2017 by +# Aric Hagberg <hagberg@lanl.gov> +# Dan Schult <dschult@colgate.edu> +# Pieter Swart <swart@lanl.gov> +# All rights reserved. +# BSD license. + +import matplotlib.pyplot as plt +from networkx import nx + +z = [5, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1] +print(nx.is_valid_degree_sequence(z)) + +print("Configuration model") +G = nx.configuration_model(z) # configuration model +degree_sequence = [d for n, d in G.degree()] # degree sequence +print("Degree sequence %s" % degree_sequence) +print("Degree histogram") +hist = {} +for d in degree_sequence: + if d in hist: + hist[d] += 1 + else: + hist[d] = 1 +print("degree #nodes") +for d in hist: + print('%d %d' % (d, hist[d])) + +nx.draw(G) +plt.show() |
