4.0

4.0 | 7 ratings Rate this file 13 Downloads (last 30 days) File Size: 1.49 KB File ID: #19476

Colored line or scatter plot

by Pekka Kumpulainen

 

07 Apr 2008 (Updated 07 Apr 2008)

Plot lines with CData, (actually surface)

| Watch this File

File Information
Description

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

Examples:
x = 0:0.1:2*pi;
color_line(x,sin(x),sin(x))
color_line(x,cos(x),cos(x),'*')

Acknowledgements
This submission has inspired the following:
3D colored line plot
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
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.

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.

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

20 Mar 2009 Tristan Desrues

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!!

03 Apr 2009 Georg Stillfried

Nice. Just what I needed!

14 Jul 2009 David

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

04 Nov 2010 Shinya Ito

Exactly what I was looking for! Thanks!

29 Nov 2011 Ulrich

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

For example:

x = 1:301
color_line(x,sin(x),cos(x))

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

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

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
specialized Pekka Kumpulainen 22 Oct 2008 09:56:35
plotting Pekka Kumpulainen 22 Oct 2008 09:56:35
color line Pekka Kumpulainen 22 Oct 2008 09:56:35
cdata Pekka Kumpulainen 22 Oct 2008 09:56:35
plot Pekka Kumpulainen 22 Oct 2008 09:56:35
graphics Pekka Kumpulainen 22 Oct 2008 09:56:35
surface Pekka Kumpulainen 22 Oct 2008 09:56:35
object Pekka Kumpulainen 22 Oct 2008 09:56:35
lines Pekka Kumpulainen 22 Oct 2008 09:56:35
cdata Georg Stillfried 06 Apr 2009 04:02:10

Contact us at files@mathworks.com