專案節點的度中心性分佈
現在要為 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()