Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / examples / drawing / plot_degree_rank.py @ 5cef0f13

History | View | Annotate | Download (832 Bytes)

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

7
Random graph from given degree sequence.
8
Draw degree rank plot and graph with matplotlib.
9
"""
10
# Author: Aric Hagberg <aric.hagberg@gmail.com>
11
import networkx as nx
12
import matplotlib.pyplot as plt
13

    
14
G = nx.gnp_random_graph(100, 0.02)
15

    
16
degree_sequence = sorted([d for n, d in G.degree()], reverse=True)
17
# print "Degree sequence", degree_sequence
18
dmax = max(degree_sequence)
19

    
20
plt.loglog(degree_sequence, 'b-', marker='o')
21
plt.title("Degree rank plot")
22
plt.ylabel("degree")
23
plt.xlabel("rank")
24

    
25
# draw graph in inset
26
plt.axes([0.45, 0.45, 0.45, 0.45])
27
Gcc = sorted(nx.connected_component_subgraphs(G), key=len, reverse=True)[0]
28
pos = nx.spring_layout(Gcc)
29
plt.axis('off')
30
nx.draw_networkx_nodes(Gcc, pos, node_size=20)
31
nx.draw_networkx_edges(Gcc, pos, alpha=0.4)
32

    
33
plt.show()