Code covered by the BSD License  

Highlights from
Color coded 3D scatterplot

4.79167

4.8 | 25 ratings Rate this file 130 Downloads (last 30 days) File Size: 4.77 KB File ID: #9519
image thumbnail

Color coded 3D scatterplot

by Ken Garrard

 

05 Jan 2006 (Updated 14 Oct 2011)

Produces a 3D scatterplot of XYZ data with varying colors

| Watch this File

File Information
Description

A 3D scatter plot of a Cartesian data set is drawn. The data points are sorted by color so that plot3 is called once for each group of points that map to the same color. Execution time is significantly reduced for large data sets. By default the points are colored according to their distance from the XY plane. This can changed with the 'ColorData' property. Additionally the upper and lower limits of the color range can be specified. This is useful for creating a series of plots with the same coloring.

The example plot is produced by the following code.

   figure('color','white');
   [x,y,z] = peaks(101);
   c = gradient(z);
   k = hypot(x,y)<3;
   plot3k({x(k) y(k) z(k)},...
      'ColorData',c(k),'ColorRange',[-0.5 0.5],'Marker',{'o',2},...
      'Labels',{'Peaks','Radius','','Intensity','Lux'},...
      'PlotProps',{'FontSize',12});

Plot3k is based on plot3c by Uli Theune.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
plot3c

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (27)
07 Feb 2006 oh kwoun  
05 Apr 2006 Daniel B

Great function. Work well and is fast.

10 May 2006 Josiah Yoder

Just what I was looking for - works great.

05 Jun 2006 sylvio berlusconi

your are a genious

15 Feb 2007 Matteo Tajana

thank you, I've been looking for such a function for ages! ;-)

12 Jul 2007 Alexander K.

Very useful function

13 Jul 2007 Eric DeGiuli

Great, does just what I wanted.

12 Dec 2007 Joseph Marks

It "rocks"; it allows a "surf"-like plot without the hassles and inaccuracies of preppoing the dating over a regular grid!
First-rate work.

13 Feb 2008 Tim A

Thanks a lot, very useful

22 Apr 2008 Esben Almkvist

Nice!
I would add a:
if nargout>0
   g = gcf;
end
That way you get a cleaner function if you don't need the output.

07 May 2008 Mike Ross

Exactly what I was looking for. Thank you.

30 May 2008 Abel Brown

Holy Jehosaphat!! worked outta the box! The funktion did exactly what i just spent the last hour trying to do! what a fantastic function for scientifik data! you're my hero!!!!

thanks x 10!

03 Sep 2008 Shazux The Great

one that you should never miss!

01 Dec 2008 Jveer

very nice indeed! any chance of further speed optimization?

08 Dec 2008 Adam Pilchak

excellent file.
For those interested in additional functionality in terms of viewing contours and slices through 3d data, check out:
http://www.paraview.org

29 May 2009 aaaaa  
02 Sep 2009 Le

very good job! thank you!

09 Feb 2010 Alvaro Canivell

Very useful indeed !

Something I was missing in it:

- A label for the color bar, that could be passed in the 'strs' together with the title and the rest of the labels.

If somebody wants that, just tell me, I added that

Thanks again !

23 Feb 2010 Vishesh Vikas

Very good - its way quicker than scatter3. Uses much less memory :)

06 May 2010 Peng Huang

I would suggest to change "length(L)" to "size(L,1)" since when points are too less (i.e. less than 3), error will happen. Besides that, it is great! Thanks:)

22 Jul 2010 Nathan

minor grid does not show up on Z-axis when Zscale is set to log
(i.e. set(gca,'zscale','log');

any idea why this is occuring?

22 Jul 2010 Nathan  
24 Jan 2011 Joseph Miller

Simple, fast and clean. VERY good job! Thank you!

10 Feb 2011 daniel

After trying and failing to plot my data (3e6 points) using scatter3, this little guy did it for my lickety-split. Is a 4D set, so plotting first 3 dimensions as spatial, and fourth as color. Just had to make sure my nargs matched up via cells, so did {data(:,1) data(:,2) data(:,3)} as first arg to plot3k, and data(:,4) as second for color.

A+ rating from this matlab user.

12 Mar 2011 Navneet Viswan

Is it possible to use this code to scan images with laser stripe in it and plot out the 3D point cloud of the laser traced portion? with depth?

Kindly help me out

13 Jun 2011 James  
16 Aug 2011 Alexander

Great code. One small improvement:
Change length(L) to size(L,1) on 96 and 141 lines. Otherwise, it's not working with one data point

Please login to add a comment or rating.
Updates
10 Nov 2008

The color range and markersize arguments have been added. The figure handle is not returned unless an output argument is given.

14 Oct 2011

Optional arguments are property,value pairs. Input data can be a cell array, vector or matrix.

14 Oct 2011

Bug fix for 'ColorData', 'ColorRange' properties.

Tag Activity for this File
Tag Applied By Date/Time
specialized Ken Garrard 22 Oct 2008 08:11:18
plotting Ken Garrard 22 Oct 2008 08:11:18
scatterplot Ken Garrard 22 Oct 2008 08:11:18
3d Ken Garrard 22 Oct 2008 08:11:18
plot3c Ken Garrard 22 Oct 2008 08:11:18
plot3 Ken Garrard 22 Oct 2008 08:11:18
color Cristina McIntire 10 Nov 2008 12:09:42
3d Cristina McIntire 10 Nov 2008 12:18:03
specialized Tracy Zhang 11 Nov 2008 01:14:24
scatterplot Tracy Zhang 11 Nov 2008 01:14:34
3d Neyram Hemati 23 Jul 2009 18:50:58
scatterplot Mark Tschopp 04 Jun 2010 10:10:31
scatterplot Esther Kneepkens 03 Dec 2010 12:23:14
color Anitha 18 Feb 2011 01:41:18
scatterplot Larry 15 Apr 2011 17:45:02
scatterplot vittorio 31 May 2011 02:05:47

Contact us at files@mathworks.com