开始使用免费开始使用

弧形图(Arc plot)

接下来,我们用弧形图来可视化该网络。您还将练习按图中节点的排序方式进行绘制。

注意:如果实现正确,本练习大约需要 4–7 秒运行完成。

本练习是课程的一部分

Python 网络分析入门

查看课程

练习说明

  • 绘制 GitHub 协作网络的弧形图,并按作者的度数进行排序。具体步骤:
    • 遍历 G 中的所有节点,并包含元数据(指定 data=True)。
    • 在循环的每次迭代中,使用 nx.degree() 计算每个节点 n 的度数,并设置其 'degree' 属性。nx.degree() 接受两个参数:图对象和节点。
    • 通过指定两个参数创建 arc 图对象 agraph 参数为 Gsort_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()
编辑并运行代码