I found this technique very useful. It seemed relevant to the discussion at
http://blogs.mathworks.com/videos/2014/08/12/coloring-a-line-based-on-height-gradient-or-some-other-value-in-matlab/#comment-41206
where I posted a comment referencing to this submission. Thanks.

^ works fine up to million elements (didn't try with more).
The function does NOT refresh the plot. It only adds a new colored line.
Maybe you should clear the figure (clf).

Perfect !!
let you plot large dataset of coordinate, colored with velocity, in 1 line:
color_line(x,y,sqrt(vx.^2+vy.^2),'.')

instead of
for i=1:numel(x)
plot(x(i),y(i),'.','color',myColorMap(sqrt(vx(i)^2+vy(i)^2)))
end

And it's a lot faster!!
thx!!

04 Aug 2008

Carlos Adrian Vargas Aguilera

This is nice Pekka, I recommend you to include a screenshot.

My 'low' rating is because if the length of the series is short (10 elements for example) the colors are different for the same y-values. My suggestion is to generate colorbands in the y-axis and make linear interpolations in these bands.

Regards, Carlos

31 Jul 2008

Ed Mackay

Useful function which avoids creating separate line segments for each color. The coloured line produced is a single MATLAB graphics object.

14 Apr 2008

d luc

thanks--this is a useful routine for plotting 2-d vectors (e.g. U=[u,v]) on a [u,v] plane, where the color gives the sense of rotation (time evolution) of the vector.