In [2]:
import warnings
warnings.filterwarnings('ignore')


import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

Exercício 01: Faça o gráfico da distribuição de nós das redes abaixo. Indique se segue a lei de potência.

In [16]:
fig = plt.figure(1); plt.clf()
nrows = 6
ncols = 2
fig, ax = plt.subplots(nrows, ncols, figsize=(15,30))
idx = np.arange(0,nrows*ncols,2)
nodes = [10, 10, 12, 10, 12, 14]
probs = [0.2, 0.4, 0.6, 1, 2, 2]

for ix, n_nodes, p in zip(idx, nodes, probs):  
    if p >= 1:
        G = nx.barabasi_albert_graph(n_nodes, p)
    else:
        G = nx.fast_gnp_random_graph(n_nodes, p)
        
       
    degree_sequence=sorted(nx.degree(G).values(),reverse=True) 
    dmax=max(degree_sequence)
    ax[ix/ncols, ix%ncols+1].hist(degree_sequence)#plot(degree_sequence,'b-',marker='o')

    nx.draw_circular(G, with_labels=True, ax=ax[ix/ncols, ix%ncols])
<matplotlib.figure.Figure at 0x7f0088ce89b0>
In [ ]: