Code covered by the BSD License  

Highlights from
scatter3sph

4.5

4.5 | 2 ratings Rate this file 22 Downloads (last 30 days) File Size: 2.09 KB File ID: #27112
image thumbnail

scatter3sph

by Francisco de Castro

 

29 Mar 2010 (Updated 15 Sep 2010)

SCATTER3SPH Plots a 3d scatter plot with 3D spheres of different size and color

| Watch this File

File Information
Description

Little function to plot a 3D scatter of semi-transparent spheres (as opposed to dots). Very improvable, specially regarding adding optional parameters for the spheres characteristics: number of facets, transparency, etc. It can represent three quantities as: height (Z), color and size for each combination of two variables (X and Y).

SCATTER3SPH is like scatter3 only drawing spheres with volume, instead of flat circles, at coordinates specified by vectors X, Y, Z. All three vectors have to be of the same length.
SCATTER3SPH(X,Y,Z) draws the spheres with the default size and color.
SCATTER3SPH(X,Y,Z,'size',S) draws the spheres with sizes S. If length(S)= 1 the same size is used for all spheres.
SCATTER3SPH(X,Y,Z,'color',C) draws the spheres with colors specified in a N-by-3 matrix C as RGB values.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
30 Mar 2010 Rob Campbell

Nice. I have used plot similar to this in the past and found them useful. Never got around to writing a separate function for the job, however.

11 May 2010 Allen

Spheres change shape with change in view orientation.

12 May 2010 John D'Errico

I saw Allen's comment, and I had to respond here. The "change" in shape is not a reflection on this code, but of the auto-scaling of MATLAB when it chooses the plot axes if your variables have different units.

If you wish to avoid that, then there are several things you can do. On 3-d plots that will be rotated, you might choose to execute the command

axis vis3d

after the scatter3ph call. This makes rotation more smooth anyway, and it prevents other problems in the rotation.

To enforce the sphere to look truly spherical from any orientation instead of ellipsoidal, then execute the command

axis equal

after the call to scatter3ph. Since both of these axis commands have other side affects, I am not recommending to the author to include them in the code. They are best left to the discretion of the user to apply as they wish or not.

In my opinion, this code has good help, an H1 line, error checks. I found only one glitch, a minor one at that. A standard paradigm in the MATLAB interface is that when you use property/value pairs to provide input parameters, here 'color','size', that you should allow the user to shorten those parameter names as long as the shortening is unambiguous. Thus we should be able to specify 'size' as any of 'siz', 'si', or 's'. In addition, caps should be ignored. So it should be acceptable to specify 'SIZE', or 'Size', or even 'SiZe' if the user chooses to do so. Since insensitivity to case takes nothing more than the use of the lower function in your code, that is a trivial fix. And there are several easy ways to test for a shortened property name. strmatch or strcmp or strcmpi all let you do it very efficiently. I have even seen it done in the switch statement itself, forming the case sub-statement as perhaps

    case {'s' 'si' 'siz' 'size'}

My rating of 4 for this matter may seem too much of a drop for a problem that does not affect the usability of the code, but it makes sense to be consistent in your interface with the many other tools that MATLAB supplies. This way it is easy for others to use your code. I'll watch for updates as always, and will be happy to raise my rating to a 5 if this behavior is repaired.

15 Sep 2010 Francisco de Castro

Actually, there is another function in File Exchange which does a better job than mine: BUBBLEPLOT3 by Peter Bodin. Check it out.

15 Sep 2010 Matteo Niccoli

Very nice of you to point to BUBBLEPLOT3 Francisco. Very much in line wit the spirit of this community.

03 Mar 2011 Meggy Dessagne

very useful, thanks a lot.
Just a little issue: I noticed that when I add 'size' property, the scatter displays one big bubble instead of 28 as contained in x,y,z. When I removed 'size' property it works well with all bubbles of the same size.
Any idea about how to use 'size' property without drawing only one bubble?

Please login to add a comment or rating.
Updates
31 Mar 2010

Change figure and description to better describe the utility of the function

15 Sep 2010

Heeding John D'Errico comments, now parameter names can be abbreviated (to 3 letters) and their case is irrelevant.

Tag Activity for this File
Tag Applied By Date/Time
scatter scatter3 plot sphere 3d figure Francisco de Castro 29 Mar 2010 10:56:37

Contact us at files@mathworks.com