【问题标题】:Plotting subgraphs identified by connected components绘制由连通分量标识的子图
【发布时间】:2021-08-29 11:58:59
【问题描述】:

我在图表中检测到连接的组件。 现在我需要将它们绘制在单独的图表中以单独分析它们。例如,我使用的是空手道俱乐部网络,但我的网络实际上有 5 个连接的组件。

G = nx.karate_club_graph() 

connected_com=[len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)]
S = [G.subgraph(c).copy() for c in nx.connected_components(G)] 

我使用了 nx.draw 但没有显示任何内容:

plt.figure()
nx.draw(S)
plt.show()

【问题讨论】:

    标签: python matplotlib networkx


    【解决方案1】:

    S 不是子图,而是子图列表,因此即使只有一个子图,您也必须遍历列表(karate_club_graph 数据集就是这种情况):

    plt.figure()
    for s in S:
        nx.draw(s)
    plt.show()
    
    # For this dataset, nx.draw(G) give the same result
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      相关资源
      最近更新 更多