概述
目前我所拥有的是这样的:
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 graph nx.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 – 网络特定节点标签所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧