Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / examples / advanced / plot_eigenvalues.py @ 5cef0f13

History | View | Annotate | Download (505 Bytes)

1
"""
2
===========
3
Eigenvalues
4
===========
5

6
Create an G{n,m} random graph and compute the eigenvalues.
7
"""
8
import matplotlib.pyplot as plt
9
import networkx as nx
10
import numpy.linalg
11

    
12
n = 1000  # 1000 nodes
13
m = 5000  # 5000 edges
14
G = nx.gnm_random_graph(n, m)
15

    
16
L = nx.normalized_laplacian_matrix(G)
17
e = numpy.linalg.eigvals(L.A)
18
print("Largest eigenvalue:", max(e))
19
print("Smallest eigenvalue:", min(e))
20
plt.hist(e, bins=100)  # histogram with 100 bins
21
plt.xlim(0, 2)  # eigenvalues between 0 and 2
22
plt.show()