问题描述
我正在使用 networkx 包来计算社区网络的频率计数,使用余弦相似度下面是我尝试绘制网络图的代码部分,但出现此错误。
S=nx.Graph() # draws the community detection graph
S.add_nodes_from(names)
S.add_weighted_edges_from(sim_edges)
pos1 = nx.spring_layout(S)
plt.figure(figsize=(10,10),dpi=200)
part = community_louvain.best_partition(S)
values = [part.get(node) for node in S.nodes()]
nx.draw_networkx_nodes(S,pos=pos1,node_color = values,node_size=8400,cmap =cmap1)
nx.draw_networkx_labels(S,font_size=10)
nx.draw_networkx_edges(S,edgelist=edge_weights.keys(),width=list(edge_weights.values()))
plt.axis('off')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-32-ae3fd091a221> in <module>
47 values = [part.get(node) for node in S.nodes()] #get all names in network go to the partition get entry from the partitionget entry with node name - values is a list of entries that were the value in partition got by looking up each node name in network
48 nx.draw_networkx_nodes(S,cmap =cmap1) #colour nodes by which community they in
---> 49 nx.draw_networkx_labels(S,font_size=10)
50 nx.draw_networkx_edges(S,width=list(edge_weights.values())) #keys are the edges and weights are values -edge weight dcitionary get edges and values
51 plt.axis('off')
TypeError: draw_networkx_labels() got an unexpected keyword argument 'node_color'
解决方法
来自网络X documentation on draw_networkx_labels
,
可用参数不包括 node_color
,如果需要,您可以更改字体颜色及其透明度:
font_color (string) – 字体颜色字符串(默认 = 'k' black)
alpha (float or None) – 文本透明度(默认=无)