NetworkX 节点属性图 [英] NetworkX node attribute drawing

查看:111
本文介绍了NetworkX 节点属性图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 networkx 进行可视化.当我使用该功能时我看到了draw_networkx_edge_labels我可以检索边的标签.

Im using networkx for visualization. I see when I use the function draw_networkx_edge_labels I can retrieve the labels for edges.

我想在节点上打印属性(而不是标签).尝试几乎所有内容.仍然卡住.如果我每个节点有 5 个属性,是否可以在每个节点上打印特定属性?例如,如果一个汽车节点有属性:尺寸、价格、公司、..我想在每个节点上打印汽车的尺寸?

I want to print the attribute on node ( instead of the label).. try everything almost . still stuck. If i have 5 attributes per node, is there anyway I can print a specific attribute on each node ? For example, if a car node has attributes: size, price, company, .. I want to print the size of the car on each node ?

不知道能不能把这个输出到图上.

Don't know whether can output this on graph.

推荐答案

你可以通过指定labels=关键字来实现

You can do it by specifying the labels= keyword

import pylab
import networkx as nx
G=nx.Graph()
G.add_node('Golf',size='small')
G.add_node('Hummer',size='huge')
G.add_edge('Golf','Hummer')
labels = nx.get_node_attributes(G, 'size') 
nx.draw(G,labels=labels,node_size=1000)
pylab.show()

这篇关于NetworkX 节点属性图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆