开始使用免费开始使用

可视化论坛投影的度中心性分布

本练习继续巩固度中心性与投影的概念。这一次,您将绘制 '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()  
编辑并运行代码