Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Colored line or scatter plot

4.2 | 9 ratings Rate this file 38 Downloads (last 30 days) File Size: 1.49 KB File ID: #19476 Version: 1.0

Colored line or scatter plot



07 Apr 2008 (Updated )

Plot lines with CData, (actually surface)

| Watch this File

File Information

plots a 2-D "line" with c-data as color
Makes a surface object and the colouring is controlled by the colormap.

x = 0:0.1:2*pi;


This file inspired 3 D Colored Line Plot.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
19 Aug 2014 Julian

Julian (view profile)

I found this technique very useful. It seemed relevant to the discussion at
where I posted a comment referencing to this submission. Thanks.

29 Aug 2013 Yilong Jia

Works pretty well for my system. Thanks!

26 Jan 2012 Pekka Kumpulainen

^ 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).

Comment only
29 Nov 2011 Ulrich

Ulrich (view profile)

Unfortunately in my hands this function only seems to work for x shorter than 300 elements.

For example:

x = 1:301

never generates a plot(i.e. the plot window never refreshes.)

For x=1:300 it works beautifully though.
Is there a simply way to make it work for longer x (e.g. 2500 points).

04 Nov 2010 Shinya Ito

Exactly what I was looking for! Thanks!

14 Jul 2009 David

David (view profile)

Doesn't seem to work with R2008b. The following is returned for the example:

Warning: size(CData) must equal size(ZData) or size(ZData)-1 for flat shading

Comment only
03 Apr 2009 Georg Stillfried

Nice. Just what I needed!

20 Mar 2009 Tristan Desrues

Perfect !!
let you plot large dataset of coordinate, colored with velocity, in 1 line:

instead of
for i=1:numel(x)

And it's a lot faster!!

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.

Contact us