Circos 图
最后,您将为该网络绘制一幅 Circos 图!
本练习是课程的一部分
Python 网络分析入门
练习说明
- 为该网络绘制一幅 Circos 图。再次按节点的度数对 GitHub 用户排序,并按其
'grouping'键进行分组和着色。具体步骤:- 遍历
G中包含元数据的所有节点(指定data=True)。 - 在循环的每次迭代中,使用
nx.degree()计算每个节点n的度,并设置其'degree'属性。 - 通过在图
G之外再指定 3 个参数来创建circos图对象c:sort_by(取值为'degree')、group_by和node_color_by(二者均取值为'grouping')。 - 将
Circos图绘制到屏幕上。
- 遍历
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import necessary modules
from nxviz import circos
import matplotlib.pyplot as plt
# Iterate over all the nodes, including the metadata
for n, d in ____:
# Calculate the degree of each node: G.node[n]['degree']
____ = ____
# Create the Circos plot: c
c = ____
# Draw the Circos plot to the screen
____
plt.show()