我以.json文件的形式將我的Facebook數據導入到了我的計算機上。該數據的格式爲:節點大小取決於NetworkX上的節點度數
{"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)
沒有工作,我想不出其他的方法。
很好的回答!正如我在下面提到的那樣,如果數據具有用戶想要顯示的零度節點,則節點大小應該添加一些值,例如:在d.values()中v的[[(v + 1)* 100) ]',以便零度節點出現。 – Tchotchke