我分析了我的图并得到了特征向量中心点。(如下所示)
cit = nx.read_edgelist('Cit-HepTh.txt', create_using=nx.DiGraph(), nodetype=int)
(...compute centrality to a dict...)
现在,我要根据此命令绘制图形,其中不同的节点根据其中心性而具有不同的大小。
我看到了一个绘制不同颜色的示例(也许我认为有一种相似的方法可以绘制不同的大小
node_colours = []
for node in nodes:
if node < 5:
node_colours.append('blue')
else:
node_colours.append('green')
#draw graph, substitute the single colour with ur list of colours
nx.draw_spring(G, k=1, node_color = node_colours,
node_size = 200, font_size = 6, with_labels = True)
我正在尝试绘制一个包含27000+个节点的大图,但是为networkX绘制这样的图似乎很慢。所以我只想绘制前100位(最高eigenVector中心性)。 您有任何示例或建议吗?
答案 0 :(得分:3)
这些行上的内容(虽然有27k +节点,但又很快又很脏):
通过以下方式获得每个节点的中心点之后:
eigen_centrality = nx.eigenvector_centrality(G)
all_nodes = [(node,eigen_centrality(node)) for node in eigen_centrality]
按中心度查找前100个节点:
top_100_nodes = [n for (n,c) in all_nodes if c in np.argsort(c)[-100:]]
然后,创建前100个节点的子图:
G1 = G.subgraph(top_100_nodes)
然后绘制图形:
top_100_centrality = nx.eigenvector_centrality(G1)
nx.draw_spring(G1, k =1, node_color = node_colours, \
node_size = [top_100_centrality(n) for n in G1.nodes()],
font_size = 6, with_labels = True)