Lines of different colors in the same Scatter object


I’m currently making a network visualization ; I started from this tutorial and after a few modifications, managed to obtain my figure. The point is that I want to color the edges according to some values, but here they are all of the same color. It deals with this Scatter object :

edge_trace = go.Scatter(
    line=dict(width=0.5, color='#888'),

I loop on my values to fill the edge_trace['x'] and edge_trace['y'] list of coordinates, and I tried to do the same with the edge_trace[line]['color'] attribute instead of only specifying a single color. But it gave me an error. How can I do that ? Do I have to create a Scatter object for each edge of the graph ?


Hi @Micawber,

Unfortunately it’s not possible to change line colors within a single scatter trace. So you would need to use multiple traces.

Here are some notes for an approach to doing this that I think would be pretty efficient:

I would eventually love to have a dedicated graph/directed graph figure factory that would do this discretization under the hood. Let me know if you would be interested in helping out with it :slightly_smiling_face:


Hi @jmmease,

Thank you for your answer ! I have modified my code to have distinct traces and it works now :). i’d like to help that kind of figure but unfortunately I think I’m too busy with my PhD right now !


1 Like

@jmmease any updates since last year?

@jmmease all the tutorials I see specify how to set a scatter trace’s color for the markers. How do I set a scatter trace’s color for lines using continuous values? I can’t figure out how to make colorscale work.

@jmmease Is this a feature the plotly team might consider adding?