ZhenKai
ZhenKai

Reputation: 135

Plot size of each node according to dictionary

So far I have the following code:

source = ['0','0','0','0','0','0','0']
destination = ['1','2','3','4','5','6','7']

FB_network_graph = pd.DataFrame({ 'from':source, 'to':destination})
G=nx.from_pandas_edgelist(FB_network_graph, 'from', 'to')

plt.figure(figsize = (100,100))
nx.draw(G, with_labels=True)

I want to plot a graph whereby node '0' has a size of 7 and node '1'-'7' has a size of 1.

Upvotes: 2

Views: 163

Answers (1)

yatu
yatu

Reputation: 88236

It looks like you want to adjust the node_size according to the degree. For that you can define a dictionary from the result of G.degree and set the size according to the corresponding node degree by looking up the dictionary:

scale = 300
d = dict(G.degree)
nx.draw(G, node_color='lightblue', 
        with_labels=True, 
        nodelist=d, 
        node_size=[d[k]*scale for k in d])

enter image description here

Alternatively you could just define your custom dictionary, to set the corresponding node sizes in node_size. For this specific case with something like:

d = {str(k):1 for k in range(1,8)}
d['0'] = 7

Upvotes: 1

Related Questions