開始使用免費開始

專案節點的度中心性分佈

現在要為 G'projects' 分區繪製度中心性分佈圖。步驟和上一個練習完全相同。為了方便你,matplotlib.pyplot 已經預先以 plt 匯入。

開始動手吧!

本練習屬於課程

Python 網路分析進階

檢視課程

練習說明

  • 取得一個名為 project_nodes 的清單,對應到 G 中屬於 'projects' 的節點。
  • 使用 nx.degree_centrality() 計算 G 中每個節點的度中心性,並將結果存為 dcs
  • 使用串列生成式計算 project_nodes 中每個節點的度中心性,並將結果存為 project_dcs
  • 使用 plt.hist()project_dcs 繪製專案的度分佈直方圖。

動手互動練習

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

# Get the 'projects' nodes: project_nodes
project_nodes = ____

# Compute the degree centralities: dcs
dcs = ____

# Get the degree centralities for project_nodes: project_dcs
project_dcs = [____]

# Plot the degree distribution of project_dcs
plt.yscale('log')
plt.hist(____, bins=20)
plt.show()
編輯並執行程式碼