如何在 Python 中使用 Igraph 包仅绘制更大的社区?

How to plot only bigger communities with Igraph package in Python?

我是网络世界的新手,我需要有关 python 包 Igraph 的帮助。 我创建了我的网络并应用 community_walktrap() 进行聚类。现在,我只想绘制元素超过 10 个的簇。你知道我该怎么做吗? 为了绘制所有内容,我正在使用:

ig.plot(clusters, mark_groups = True, bbox=(1000,1000), vertex_label=g.vs['name'])

但是不知道有没有什么办法可以排除较小的簇

提前谢谢你!

不幸的是,它并不像它应该的那么简单,但这里有一个快速草图:

def subgraph_of_large_clusters(clustering: VertexClustering, threshold: int) -> VertexClustering:
    sizes = clustering.sizes()
    members = [i for i, c in enumerate(clustering.membership) if sizes[c] >= threshold]
    new_graph = clustering.graph.subgraph(members)
    new_membership = [clustering.membership[i] for i in members]
    return VertexClustering(new_graph, new_membership)

g = Graph.GRG(10000, 0.02)
cl = g.community_walktrap().as_clustering()
plot(subgraph_of_large_clusters(cl, 100))