使用 nxviz 可视化已筛选的图
本练习将使用 circos 图来可视化已筛选的图。circos 图非常适合这种可视化:您可以通过节点分组与着色来展示分区;同时,环形布局能很好地保持整体美观。
本练习是课程的一部分
Python 网络分析中级
练习说明
- 使用二部图模块的度中心性来计算每个节点的度中心性分数,但以原始图中的度中心性为基础。
- 为此使用
nx.bipartite.degree_centrality()函数,并传入参数G和nodes=forum_nodes。
- 为此使用
- 新建一个
circos图:按其分区标签('bipartite')对节点着色与分组(参数node_color_by与group_by),并按其度中心性('dc')排序(参数sort_by),然后将其显示出来。- 为确保显示时节点可见,我们已包含参数
node_enc_kwargs={'radius': 10}。
- 为确保显示时节点可见,我们已包含参数
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import necessary modules
from nxviz import circos
import networkx as nx
import matplotlib.pyplot as plt
# Compute degree centrality scores of each node
dcs = ____(____, nodes=____)
for n, d in G_sub.nodes(data=True):
G_sub.nodes[n]['dc'] = dcs[n]
# Create the circos plot: c
c = _____(___, _____, _____, _____, node_enc_kwargs={'radius': 5})
# Display the plot
plt.show()