Black Lives Matter. Please consider donating to Black Girls Code today.

Changing color of a single line graph

I need a single line to change color from point to point as it moves to the right in a spectral manner. Is this possible with Plotly and is there an example? I am able to do this using Bokeh.

Solved this one by making 50 little lines using:

        for x in range(1, 100, 2):
            fig.add_trace(go.Scatter(x=[x-1, x, x+1],
                                     y=pctg[x-1:x+2],
                                     line={'color': self.dash.palette[int(x*2.56)]

If there were another cleaner way, that would be cool.

Recollecting now, I am pretty sure this is how I did it with Bokeh :wink:

At the moment, we don’t support coloring individual line segments within a line with different colors, so the way you did it above would be the best way forward today.