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.
Deze oefening maakt deel uit van de cursus
Intermediate Network Analysis in Python
Oefeninstructies
- Create a list of degree centrality scores month-by-month. To do this:
- In each iteration of the first
forloop, compute the degree centrality ofGusing thenx.degree_centrality()function. Save the result ascent. - Append
centto the listcents.
- In each iteration of the first
- Plot ECDFs over time. To do this:
- Iterate over
range(len(cents))using aforloop. Inside the loop, use theECDF()function withcents[i].values()as the argument. Unpack the output of this intoxandy. - Pass
xandyas arguments toplt.plot().
- Iterate over
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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()