0

I want to create a 2D line plot in python using two arrays x and y. The line should have multiple colors based on a third array z and then add a colorbar next to the plot. The line colors between two point will have a smooth transition (linear interpolation) between the colors of the two points.

I have found this How to change data points color based on some variable

However it only works with individual points and it does not create a line.

Furthermore I have found the multicolored line( https://matplotlib.org/stable/gallery/lines_bars_and_markers/multicolored_line.html). This is somehow what I want but with the exception that I don't want to give the color value of a line segment. Instead I want to give the color value of a point (through the z array) and then the line should be colored automatically. Is there an easy way for this task?

Thanks

mavroui
  • 1
  • 1
  • 1
    There is no automatic "color transition for the line between two colored points" function. You have to implement this yourself by creating a number of smaller line segments with gradual color change. – Mr. T Apr 17 '22 at 09:47
  • Scikit-image will give you a list of the points along a line. I guess you could work out the colours from your `z` array yourself... maybe? https://scikit-image.org/docs/dev/api/skimage.draw.html?highlight=line#skimage.draw.line – Mark Setchell Apr 17 '22 at 11:04

0 Answers0