I am pretty novice in Python and started learning networkx to plot a graph, or road network. I have to specify, the node positions. The edge color should be dependent on the values of the edges. I tried using pandas dataframe to generate edges. The edge colors work fine when position is not specified. An example is attached.
When not specifying positions
# Build a dataframe with your connections
df = pd.DataFrame({ 'from':['A', 'B', 'C','A'], 'to':['D', 'A', 'E','C'], 'value':[1, 10, 5, 5]})
df
# Build your graph
G=nx.from_pandas_edgelist(df, 'from', 'to', create_using=nx.Graph() )
# Custom the nodes:
nx.draw(G, with_labels=True, node_color='skyblue', node_size=1500, edge_color=df['value'], width=10.0, edge_cmap=plt.cm.Blues)
Here the edge colors are perfect
When specifying positions
pos = {'A': (0,1), 'D': (1,2) , 'B': (2,3) , 'C': (6,5), 'E': (0,0)}
nx.draw(G, pos, with_labels=True, node_color='skyblue', node_size=1500, edge_color=df['value'], width=10.0, edge_cmap=plt.cm.Blues)
Here node positions are perfect, but edge colors according to value are wrong:
I also tried putting position like the following -
df2 = pd.DataFrame({ "Nodes": ['A','D','B','C','E'], "x": [0,1,2,6,0], "y": [1,2,3,5,0]})
for i in df2.index:
G.add_node(df2.loc[i, "Nodes"], df2=(nodes.loc[i, "x"], df2.loc[i, "y"]))
But, the problem in output remains they same.



