diff options
| author | Jarrod Millman <jarrod.millman@gmail.com> | 2020-12-06 22:21:52 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-06 22:21:52 -0800 |
| commit | db9790038bbf5247ce3f629fa4dd42f356d1ad17 (patch) | |
| tree | c5796315ce167db7ea0a3bbe56c8288f7412f533 /examples/drawing/plot_eigenvalues.py | |
| parent | 06d49256914be9d4a02ee5d82848a609d96aa1b5 (diff) | |
| download | networkx-db9790038bbf5247ce3f629fa4dd42f356d1ad17.tar.gz | |
Remove advanced example section (#4429)
Diffstat (limited to 'examples/drawing/plot_eigenvalues.py')
| -rw-r--r-- | examples/drawing/plot_eigenvalues.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/drawing/plot_eigenvalues.py b/examples/drawing/plot_eigenvalues.py new file mode 100644 index 00000000..b0df67ae --- /dev/null +++ b/examples/drawing/plot_eigenvalues.py @@ -0,0 +1,22 @@ +""" +=========== +Eigenvalues +=========== + +Create an G{n,m} random graph and compute the eigenvalues. +""" +import matplotlib.pyplot as plt +import networkx as nx +import numpy.linalg + +n = 1000 # 1000 nodes +m = 5000 # 5000 edges +G = nx.gnm_random_graph(n, m, seed=5040) # Seed for reproducibility + +L = nx.normalized_laplacian_matrix(G) +e = numpy.linalg.eigvals(L.A) +print("Largest eigenvalue:", max(e)) +print("Smallest eigenvalue:", min(e)) +plt.hist(e, bins=100) # histogram with 100 bins +plt.xlim(0, 2) # eigenvalues between 0 and 2 +plt.show() |
