'Different color for each line segment in plotly

I am trying to produce a 3D graph of a line where each line segment has a different (solid) color.

I am using this code:

x <- c(10,10,15,15,17,17,15,15,10,10)
y <- c(10,10,20,20,15,15,20,20,10,10)
z <- c(0.0,  7.0,  7.5, 12.0, 12.5, 12.8, 13.0, 16.0, 16.5, 24.0)
fig <- plot_ly(data.frame(x,y,z), x = ~x, y = ~y, z = ~z, type = 'scatter3d', mode = 'lines+markers',
               
               line = list(width = 6, color = c("green","red","blue","yellow","purple","pink","red","orange","magenta","cyan")),
               
               marker = list(size = 5, cmin = -20, cmax = 50))
fig

So far, the code produces gradients in each segment (see attached image), however, I would like to have a solid color.

Line segments with gradients

Is there any way to achieve this?

PS. Breaking down the polyline in multiple single-segment lines is not an option.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source