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