在投影圖上繪製度數中心性
在這裡,你要比較以下各圖的度數中心性分佈:原始圖 G、人物圖投影 peopleG,以及社團圖投影 clubsG。這會幫助你加深對二分圖與單分圖版本的度數中心性度量,其計算方式差異的理解。節點清單 people 和 clubs 已為你預先載入。
回憶影片內容:二分圖相關函式需要你傳入一個節點容器,但仍會回傳所有節點的度數中心性分數。另外請記得,度數中心性分數會以字典形式儲存(將節點對應到分數)。
本練習屬於課程
Python 網路分析進階
練習說明
- 使用 bipartite 模組的
degree_centrality(nx.bipartite.degree_centrality())繪製原始圖G的度數中心性分佈。它需要兩個引數:圖G,以及其中一個節點清單(people或clubs)。 - 使用 NetworkX 提供的一般(非二分圖)
degree_centrality(nx.degree_centrality())繪製peopleG的度數中心性分佈。 - 使用 NetworkX 提供的一般(非二分圖)
degree_centrality(nx.degree_centrality())繪製clubsG的度數中心性分佈。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import matplotlib.pyplot as plt
# Plot the degree centrality distribution of both node partitions from the original graph
plt.figure()
original_dc = ____
# Remember that you can directly plot dictionary values.
plt.hist(____, alpha=0.5)
plt.yscale('log')
plt.title('Bipartite degree centrality')
plt.show()
# Plot the degree centrality distribution of the peopleG graph
plt.figure()
people_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of people partition')
plt.show()
# Plot the degree centrality distribution of the clubsG graph
plt.figure()
clubs_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of clubs partition')
plt.show()