如何解决Python +网络图:使用大量节点
我正在使用 Networkx 创建具有20-50k个节点并且它们之间有很多连接的图形。 我在此图中的主要目标是快速找到连接到许多其他节点的节点。 我正在使用两种主要的节点类型:“帐户”(黑色)和“属性”(红色)
我遇到的问题是生成的图形不容易阅读,它们太“紧”。 我曾尝试使用“节点类型”分段使用shell_layout和二分布局,但结果根本不可读。
是使用更少节点的唯一解决方案吗? 您对我的问题有什么建议吗?
一个不错的选择:连接更紧密的节点的边缘较暗。
非常感谢您!
代码提取:
G = nx.from_pandas_edgelist(all_edges,source = "attribute",target = "account")
G.add_nodes_from(all_nodes[all_nodes['type']=='acc'].set_index('node'))
G.add_nodes_from(all_nodes[all_nodes['type']=='att'].set_index('node'))
nx.set_node_attributes(G,pd.Series(all_nodes.set_index('node').type).to_dict(),'type')
account_nodes = [n for (n,ty) in \
nx.get_node_attributes(G,'type').items() if ty == 'acc']
attribute_nodes = [n for (n,'type').items() if ty == 'att']
shells = [account_nodes,attribute_nodes]
pos = nx.shell_layout(G,shells)
nx.draw_networkx_nodes(G,pos,nodelist=account_nodes,node_size=30,alpha=1,linewidths=2,width=5,node_color='black',node_shape='o')
nx.draw_networkx_nodes(G,nodelist=attribute_nodes,node_size=10,alpha=0.4,node_color='red',node_shape='x',)
nx.draw_networkx_edges(G,width=0.1,edge_color='blue',style='solid',alpha=0.2)
双向示例:
shell示例:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。