Lines of different colors in the same Scatter object

Hello,

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(
    x=[],
    y=[],
    line=dict(width=0.5, color='#888'),
    hoverinfo='none',
    mode='lines')

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 ?

Thanks.

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: https://github.com/plotly/plotly.py/issues/591#issuecomment-430187163

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:

-Jon

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 !

M.

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?