从布拉的评论,解决方案很容易
诀窍是将标签设置在字典中,其中键是节点名称,值是您需要的标签.因此,为了仅标记集线器,代码将与此类似:
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新手像我自己:)
再次感谢布拉