network igraph & 分析
基础信息
连边(u,v);连边之间的权重:
for (u, v, d) in G.edges(data=True):
print((u, v, list(d.values())[0]))
节点信息,节点的属性
G.nodes(data=True)
如何添加节点的属性?图论算法(三):networkx 添加属性
G.add_node('g', color = 'yellow')
def set_node_country(G, nodelist_chn):
for node in G.nodes():
if node in nodelist_chn:
G.add_node(node, country='CHN')
else:
G.add_node(node, country='USA')
set_node_country(G, nodelist_chn)
assortativity_li.append(nx.attribute_assortativity_coefficient(G, "country"))
绘图
相比networkx,igraph更高效 igraph 上手教程——使用 Python 开展社会网络分析和可视化
network 的分析流程; networkx学习与使用——(5)节点和边的属性
set_node_attributes, 可以使用set node attributes 作为 labels, 详见 networkx画图时显示节点和边的属性
nx.set_node_attributes(G, labels, "labels")
nx.get_node_attributes(G, labels, "labels")
官方绘图例子:plot_snap