I imported my Facebook data onto my computer in the form of a .json file. The data is in the format:
{
"nodes": [
{"name": "Alan"},
{"name": "Bob"}
],
"links": [
{"source": 0, "target: 1"}
]
}
Then, I use this function:
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
nodes = data["nodes"]
G.add_nodes_from([n["name"] for n in nodes])
G.add_edges_from(
[
nodes[e["source"]]["name"],
nodes[e["target"]]["name"]) for e in data["links"]
]
)
json_data.close()
return G
to enable this .json file to be used a graph on NetworkX. If I find the degree of the nodes, the only method I know how to use is:
degree = nx.degree(p)
Where p is the graph of all my friends. Now, I want to plot the graph such that the size of the node is the same as the degree of that node. How do I do this?
Using:
nx.draw(G, node_size=degree)
didn't work and I can't think of another method.
