I am trying to set the node size equal to nodes' degree.
My dataset is
Person1 Age Person2 Wedding
0 Adam John 3 Yao Ming Green
1 Mary Abbey 5 Adam Lebron Green
2 Samuel Bradley 24 Mary Abbey Orange
3 Lucas Barney 12 Julie Lime Yellow
4 Christopher Rice 0.9 Matt Red Green
My code for building the network is
pos=nx.spring_layout(G, k=0.20, iterations=30)
nx.draw_networkx_nodes(G, pos, node_size = degrees, nodelist=collist['value'], node_color=collist['Wedding'])
nx.draw_networkx_edges(G, pos, width = [I['Age'] for i in dict(G.edges).values()])
I tried to define the degree as follows
degrees=[]
for x in df['Person1']: # all nodes size should depend on the degree, so also for Person2. Maybe this step is wrong
deg=G.degree[x]
degrees.append(deg)
but it seems to be not a scalar.
The error is
ValueError: s must be a scalar, or the same size as x and y
EDIT: I forgot to give an example of collist['value']
:
Wedding variable value
0 Green Person1 Adam John
1 Green Person1 Mary Abbey
... ... ... ...
75 Green Person2 Yao Ming
76 Green Person2 Adam Lebron
question from:
https://stackoverflow.com/questions/65941163/node-size-depending-on-degrees 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…