consider a data frame like this:
id | source | Target | Weight |
---|---|---|---|
1 | A | B | 1 |
2 | A | C | 2 |
3 | A | D | 3 |
4 | A | E | 4 |
I want to depict a graph with networkX which shows us two things: 1-Node with more connections has a larger size, respectively. 2-Edge with more weight has a thicker line in between.
CodePudding user response:
We can set the edge_attr
to Weight when we create the Graph
Setup Used:
import networkx as nx
import pandas as pd
from matplotlib import pyplot as plt
df = pd.DataFrame({
'id': [1, 2, 3, 4],
'source': ['A', 'A', 'A', 'A'],
'Target': ['B', 'C', 'D', 'E'],
'Weight': [1, 2, 3, 4]
})