내 Facebook 데이터를 내 컴퓨터로 .json 파일 형태로 가져 왔습니다. 데이터 형식이다노드 크기는 NetworkX의 노드도에 따라 다릅니다.
{"nodes":[{"name":"Alan"},{"name":"Bob"}],"links":[{"source":0,"target:1"}]}
그리고, I는이 기능을 사용
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)
페이지 내 모든 친구의 그래프이다. 이제 노드의 크기가 노드의 크기와 같아 지도록 그래프를 플롯하려고합니다. 어떻게해야합니까?
사용 :
는nx.draw(G,node_size=degree)
작동하지 않았다 나는 다른 방법을 생각할 수 없다.
대단한 답변입니다! 아래에 언급했듯이 데이터에 사용자가 표시하고자하는 0도 노드가있는 경우 노드 크기에는 다음과 같이 몇 가지 값이 추가되어야합니다.'[((v + 1) * 100 for v for d.values () ]'로 바뀌면 0도 노드가 나타납니다. – Tchotchke