networkx设置节点的大小_节点大小取决于NetworkX上的节点度
我以.json文件的形式將我的Facebook數(shù)據(jù)導(dǎo)入我的計算機。數(shù)據(jù)格式如下:{"nodes":[{"name":"Alan"},{"name":"Bob"}],"links":[{"source":0,"target:1"}]}
然后,我使用這個函數(shù):def parse_graph(filename):
"""
Returns networkx graph object of facebook
social network in json format
"""
G = nx.Graph()
json_data=open(filename)
data = json.load(json_data)
# The nodes represent the names of the respective people
# See networkx documentation for information on add_* functions
G.add_nodes_from([n['name'] for n in data['nodes']])
G.add_edges_from([(data['nodes'][e['source']]['name'],data['nodes'][e['target']]['name']) for e in data['links']])
json_data.close()
return G
以使此.json文件能夠在NetworkX上使用圖形。如果我找到節(jié)點的階數(shù),我知道的唯一方法是:degree = nx.degree(p)
其中p是我所有朋友的圖表。現(xiàn)在,我要繪制一個圖形,使節(jié)點的大小與該節(jié)點的階數(shù)相同。我該怎么做?
使用:nx.draw(G,node_size=degree)
沒用,我想不出別的辦法。
總結(jié)
以上是生活随笔為你收集整理的networkx设置节点的大小_节点大小取决于NetworkX上的节点度的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深拷贝与浅拷贝Object.assign
- 下一篇: [NodeJs] 如何使用nodejs对