目前我所拥有的是这样的:
nx.draw(G,pos=pos,node_color='b',node_size=8,with_labels=False)for hub in hubs: nx.draw_networkx_nodes(G,pos,nodeList=[hub[0]],node_color='r')
此时的代码会更改集线器列表中节点的大小和颜色.我也想标注他们.
我尝试添加标签参数并将其值设置为集线器名称.但它没有奏效.
谢谢
解决方法 从布拉的评论,解决方案很容易诀窍是将标签设置在字典中,其中键是节点名称,值是您需要的标签.因此,为了仅标记集线器,代码将与此类似:
labels = {} for node in G.nodes(): if node in hubs: #set the node name as the key and the label as its value labels[node] = node#set the argument 'with labels' to False so you have unlabeled graphnx.draw(G,with_labels=False)#Now only add labels to the nodes you require (the hubs in my case)nx.draw_networkx_labels(G,labels,Font_size=16,Font_color='r')
我得到了我想要的是以下内容:
我希望这将有助于其他python / networkx新手像我自己:)
再次感谢布拉
总结以上是内存溢出为你收集整理的python – 网络特定节点标签全部内容,希望文章能够帮你解决python – 网络特定节点标签所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)