視覺化論壇投影的度中心性分佈
這個練習同樣是為了加強你對度中心性與投影的概念。這次你要繪製 'forum' 投影的度中心性分佈。按照上一個練習的相同步驟進行即可!
本練習屬於課程
Python 網路分析進階
練習說明
- 取得
'forum'分割中的節點,存成名為forum_nodes的清單。 - 建立論壇節點的投影圖,命名為
G_forum。 - 使用
nx.degree_centrality()計算G_forum的度中心性,並將結果存為dcs。 - 繪製度中心性值的直方圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import necessary modules
import matplotlib.pyplot as plt
import networkx as nx
# Get the forums partition's nodes: forum_nodes
forum_nodes = [____]
# Create the forum nodes projection as a graph: G_forum
G_forum = ____
# Calculate the degree centrality using nx.degree_centrality: dcs
dcs = ____
# Plot the histogram of degree centrality values
____
plt.yscale('log')
plt.show()