CommencerCommencer gratuitement

Degree centrality over time

Now, you're going to plot the degree centrality distribution over time. Remember that the ECDF function will be provided, so you won't have to implement it.

Cet exercice fait partie du cours

Intermediate Network Analysis in Python

Afficher le cours

Instructions

  • Create a list of degree centrality scores month-by-month. To do this:
    • In each iteration of the first for loop, compute the degree centrality of G using the nx.degree_centrality() function. Save the result as cent.
    • Append cent to the list cents.
  • Plot ECDFs over time. To do this:
    • Iterate over range(len(cents)) using a for loop. Inside the loop, use the ECDF() function with cents[i].values() as the argument. Unpack the output of this into x and y.
    • Pass x and y as arguments to plt.plot().

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import necessary modules
import networkx as nx
import matplotlib.pyplot as plt

# Create a list of degree centrality scores month-by-month
cents = []
for G in Gs:
    cent = ____
    ____


# Plot ECDFs over time
fig = plt.figure()
for i in ____:
    ____, ____ = ____ 
    plt.plot(____, ____, label='Month {0}'.format(i+1)) 
plt.legend()   
plt.show()
Modifier et exécuter le code