微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将属性聚类系数添加到图形并绘制图形,节点大小与 CC 成正比

如何解决将属性聚类系数添加到图形并绘制图形,节点大小与 CC 成正比

我有一个图表:

driver.find_element_by_xpath("(//div[@class='class name'])[2]")
        or
driver.find_element_by_xpath("(//div[@class='class name'])[position()=2]")
       or
'''call find elements method instead of find element which will fetch all the elements 
 with the same class and loop through each element and perform action as below'''
all_div = driver.find_elements_by_xpath("//div[@class='class name']")
for div in all_div :
  #action to perform on each element of div

我计算每个节点的聚类:

from networkx.generators.random_graphs import *
from networkx.algorithms.cluster import *

G = fast_gnp_random_graph(20,0.4)

这会产生一个数组。然后我创建一个字典,将聚类系数链接到节点:

clust_net = clustering(G)
    cluster = []
    for a in clust_net:
        cluster.append(clust_net[a])

我如何使用它来制作一个节点大小依赖于聚类系数的图?

解决方法

您可以将 node_size 关键字参数用于 nx.draw()。这需要一个值列表,用于缩放图中的节点。

您还可以稍微简化您的代码,因为目前,当您计算 node_cluster 时,它的结构与 clustering(G) 完全相同。

以下示例为图中的每个节点设置一个属性 'cc',然后绘制该图,根据该属性的值按比例缩放节点大小。

import networkx as nx

G = nx.fast_gnp_random_graph(20,0.4)

nx.set_node_attributes(G,nx.clustering(G),"cc")

nx.draw(G,node_size=[G.nodes[x]['cc']*1000 for x in G.nodes],with_labels=True)

输出:

>>> nx.clustering(G)
{0: 0.4,1: 0.37777777777777777,2: 0.3333333333333333,3: 0.26666666666666666,4: 0.3787878787878788,5: 0.34545454545454546,6: 0.4,7: 0.1,8: 0.26666666666666666,9: 0.4666666666666667,10: 0.2857142857142857,11: 0.4444444444444444,12: 0.3,13: 0.4,14: 0.6190476190476191,15: 0.4,16: 0.4,17: 0.3888888888888889,18: 0.7333333333333333,19: 0.2857142857142857}

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。