【发布时间】:2013-05-10 03:10:50
【问题描述】:
我以 .json 文件的形式将我的 Facebook 数据导入我的计算机。数据格式为:
{"nodes":[{"name":"Alan"},{"name":"Bob"}],"links":[{"source":0,"target:1"}]}
然后,我使用这个函数:
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 上使用图形。如果我找到节点的度数,我知道如何使用的唯一方法是:
degree = nx.degree(p)
p 是我所有朋友的图表。现在,我想绘制图形,使节点的大小与该节点的度数相同。我该怎么做?
使用:
nx.draw(G,node_size=degree)
没有用,我想不出其他方法。
【问题讨论】:
标签: python python-2.7 social-networking networkx