[Network Graph] Set each edge with different color


Hi everyone !

I am currently working with Plotly & networkx Python library, and I am wondering if this is possible to color each edge I created between nodes to a different color. As I can see, on networkx, the code is:

G = nx.Graph()

On the documentation, Github or on the Internet, I did not found any tips about. This is quite simple for a Node, I just have to provide a list of colors, is it the same for edges ? Any help or link for me ? :slight_smile:

Thank you all !


Hi Toshiro,
did u get any solution?Even I am searching for a solution


@vyshakc1992 To color edges with different colors, just append each one to the list data, as a different trace . A short example here:

edges=np.array([(2,3), (3, 1), (1, 0)], dtype=np.uint8)
nodes_loc=np.array([[0.3, 0.7], [1.2, 2.6], [2, 3.5], [0.85, 0.5]])
colors=['red', 'green', 'magenta']
           marker=dict(size=8, color='blue'))

edges_list=[ dict(type='scatter',
             x=[nodes_loc[e[0]][0], nodes_loc[e[1]][0]],
             y=[nodes_loc[e[0]][1], nodes_loc[e[1]][1]],
              line=dict(width=2, color=colors[k]))  for k, e in enumerate(edges)]
fig=dict(data=data, layout=layout)


Thanks a lot, Empet…:slight_smile:


Thanks @empet ! I effectively did not found my answer in the past, so this will help me a lot in the future :slight_smile: