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

Restyle line with array of colors

Let’s say we have a trace defined by a line (no markers) including gaps. Is it possible to restyle this trace in order to apply differents colors (separated by each gaps) ?

Example: x-values: [ 0, 10, gap, 20, 30 ] -> color the line with red color from 0 to 10, then blue color from 20 to 30

I have tried applying a color array (as I do with markers colors) but it didn’t work.

Any hint will help. Thanks.

EDIT: For information, I am using Plotly.js, and I am trying to ‘highlight’ a part of a line (coloring it was one way to do it)

Unfortunately, no. line.color can only be set to a string at the moment.

You’ll have to split your data into multiple traces to achieved the desired results.

You are not the first person to have asked for this feature. Subscribe to https://github.com/plotly/plotly.js/issues/147 for the latest information on potential development.