開始使用免費開始

隨時間變化的度中心性

現在你要繪製度中心性分佈隨時間的變化圖。別忘了,題目會提供 ECDF 函式,你不需要自行實作。

本練習屬於課程

Python 網路分析進階

檢視課程

練習說明

  • 建立逐月的度中心性分數清單。作法如下:
    • 在第一個 for 迴圈的每次疊代中,使用 nx.degree_centrality() 計算 G 的度中心性,並將結果存為 cent
    • cent 加入清單 cents
  • 繪製不同比例的 ECDF 曲線以觀察時間變化。作法如下:
    • 使用 for 迴圈遍歷 range(len(cents))。在迴圈內以 cents[i].values() 作為引數呼叫 ECDF(),並將輸出解包為 xy
    • xy 作為引數傳入 plt.plot()

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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()
編輯並執行程式碼