Reputation: 251
I have the following dataset:
Person1 Age Person2 Wedding
0 Adam John 3 Yao Ming Green
1 Mary Abbey 5 Adam Lebron Green
2 Samuel Bradley 24 Mary Lane Orange
3 Lucas Barney 12 Julie Lime Yellow
4 Christopher Rice 0.9 Matt Red Green
I would like to reduce the weight of size (for example dividing by 100 the original values). I am currently adding edges in the networks as follows:
G = nx.from_pandas_edgelist(df_test, source='Person1', target='Person2', edge_attr='Age')
pos=nx.spring_layout(G, k=0.30, iterations=20)
nx.draw_networkx_nodes(G, pos, node_size=900, nodelist=collist['value'], node_color=collist['Wedding'])
nx.draw_networkx_edges(G, pos, width = [i['Age'] for i in dict(G.edges).values()])
I have tried to create a new column as Age_n
by taking Age column and dividing by 100, but actually it does not work (as the edges do not change their size/weight), when I replace Age_n
in the code.
Upvotes: 0
Views: 74
Reputation: 88236
You could just divide the Age
by some factor at the same creation of the width
list, like so:
G = nx.from_pandas_edgelist(df, source='Person1', target='Person2', edge_attr='Age')
plt.figure(figsize=(12,8))
pos=nx.spring_layout(G, k=0.30, iterations=20)
nx.draw_networkx_nodes(G, pos, node_size=500)
nx.draw_networkx_labels(G, pos)
nx.draw_networkx_edges(G, pos, width = [i['Age']/2 for i in dict(G.edges).values()])
plt.box(False)
plt.show()
Though assigning a new Age
column as you're specifying does work too, since its doing the same as the above:
G = nx.from_pandas_edgelist(df.assign(Age=df.Age/2), source='Person1',
target='Person2', edge_attr='Age')
Upvotes: 1