您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – 网络特定节点标签

5b51 2022/1/14 8:23:30 python 字数 2022 阅读 581 来源 www.jb51.cc/python

我想画一个网络,我想要它是没有标签的cretin节点的例外. 目前我所拥有的是这样的: 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')

概述

目前我所拥有的是这样的:

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 – 网络特定节点标签所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶