弧形图(Arc plot)
接下来,我们用弧形图来可视化该网络。您还将练习按图中节点的排序方式进行绘制。
注意:如果实现正确,本练习大约需要 4–7 秒运行完成。
本练习是课程的一部分
Python 网络分析入门
练习说明
- 绘制 GitHub 协作网络的弧形图,并按作者的度数进行排序。具体步骤:
- 遍历
G中的所有节点,并包含元数据(指定data=True)。 - 在循环的每次迭代中,使用
nx.degree()计算每个节点n的度数,并设置其'degree'属性。nx.degree()接受两个参数:图对象和节点。 - 通过指定两个参数创建
arc图对象a:graph参数为G,sort_by参数为'degree',以便对节点进行排序。 - 将
arc图显示在屏幕上。
- 遍历
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import necessary modules
from nxviz import arc
import matplotlib.pyplot as plt
# Iterate over all the nodes in G, including the metadata
for n, d in ____:
# Calculate the degree of each node: G.node[n]['degree']
____ = ____
# Create the Arc plot: a
a = ____
# Draw the Arc plot to the screen
plt.show()