开始使用免费开始使用

在投影上绘制度中心性分布

在这里,您将比较以下图的制度中心性分布:原始图 G、人员图投影 peopleG,以及俱乐部图投影 clubsG。这将加深您对二部图与单部图在制度中心性指标计算上的差异的理解。节点列表 peopleclubs 已为您预先加载。

请回忆视频内容:二部图函数需要传入一个节点容器,但仍会返回所有节点的制度中心性分数。还要记住,制度中心性分数以字典形式存储(从节点映射到分数)。

本练习是课程的一部分

Python 网络分析中级

查看课程

练习说明

  • 使用二部图模块中的 degree_centrality 函数 nx.bipartite.degree_centrality() 绘制原始图 G 的制度中心性分布。该函数接收 2 个参数:图 G,以及节点列表之一(peopleclubs)。
  • 使用 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()
编辑并运行代码