networkx网络关系图

import networkx as nx
import matplotlib.pyplot as plt
from networkx.algorithms.community import k_clique_communities

G = nx.read_gml(‘D:\Download\dolphins\dolphins.gml’)
klist = list(k_clique_communities(G,5))

#plotting
pos = nx.spring_layout(G)
plt.clf()
nx.draw(G,pos = pos, with_labels=False)
nx.draw(G,pos = pos, nodelist = klist[0], node_color = ‘b’)
nx.draw(G,pos = pos, nodelist = klist[1], node_color = ‘y’)
plt.show()
networkx网络关系图_第1张图片

#按度调整节点大小
de = dict(G.degree()) #转换成dict
de2 = [de[v]*20 for v in sorted(de.keys(), reverse=False)]
nx.draw_networkx(G, pos, node_size=de2, with_labels = False, node_color=’#A52A2A’, linewidths=None, width=1.0, edge_color =’#858585’)
nx.draw_networkx_labels(G,pos,font_size=6,font_color=‘white’)
plt.show()
networkx网络关系图_第2张图片

你可能感兴趣的:(python)