欢迎来到RankFan的Blogs

扩大
缩小

network igraph & 分析

Graph analysis

基础信息

连边(u,v);连边之间的权重:

for (u, v, d) in G.edges(data=True):
    print((u, v, list(d.values())[0]))

节点信息,节点的属性

G.nodes(data=True)

如何添加节点的属性?图论算法(三):networkx 添加属性

assortativity

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

posted on 2022-11-17 11:01  RankFan  阅读(25)  评论(0编辑  收藏  举报

导航