'Networkx not giving correct colors based on wegiths from data frame

I am trying to create graphs of conflicts and alliances between drug trafficking organizations. I want conflicts to be graphed as red edges, and alliances to be graphed as blue edges. I gave each relationship a weight so that Networkx could give each relationship a different color. This is the edgelist I have:

But the colors shown are inconsistent with the weights. I have tried different things but nothing seems to work. This is my code:


import networkx as nx
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df=pd.read_csv("2004N.csv")
df

    Source  Target  Weight
0   Gulf Cartel     Sinaloa Cartel  -1
1   Tijuana Cartel  Sinaloa Cartel  -1
2   Gulf Cartel     Juarez Cartel   1
3   Tijuana Cartel  Gulf Cartel     1
4   Tijuana Cartel  Juarez Cartel   1
5   Juarez Cartel   Sinaloa Cartel  -1

 

G=nx.from_pandas_edgelist(df, 'Source', 'Target', edge_attr="Weight")

plt.figure(1,figsize=(12,8))

nx.draw(G, with_labels=True, node_color='skyblue', node_size=1500, edge_color=df['Weight'], width=5.0)

This is the image I get:

Color of edges are not consistent with weights

Any help will be very much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source