Code covered by the BSD License  

Highlights from
scatter3sph

4.0

4.0 | 3 ratings Rate this file 40 Downloads (last 30 days) File Size: 2.89 KB File ID: #27112
image thumbnail

scatter3sph

by

 

29 Mar 2010 (Updated )

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

| Watch this File

File Information
Description

SCATTER3SPH is like scatter3 only drawing spheres, instead of flat circles. It can represent three quantities as: height (Z), color and size for each combination of two variables (X and Y). The spheres will look 'spherical' no matter the axis scaling.
SCATTER3SPH(X,Y,Z) draws the spheres at coordinates in vectors X, Y and Z, with the default size and color. The three vectors have to be of the same length.

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.

SCATTER3SPH(X,Y,Z,'transp',T) applies transparency level 'T' to the spheres T= 0 => transparent, T= 1 => opaque.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
09 May 2014 Francisco de Castro

I uploaded a new version that does not have the problem mentioned by DBS adn Allen (I think). Spheres will always look spherical, independently of the axis scaling.

10 Nov 2012 Francisco de Castro

DBS: Just don't use different scales in the axis. This effect cannot be avoided. See D'Errico advise below.

09 Nov 2012 DBS

If you use different scales on the X,Y,Z axis, the balls will be flattened as plates... so it doesn't work for my case

15 Sep 2010 Matteo Niccoli

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

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.

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.

11 May 2010 Allen

Spheres change shape with change in view orientation.

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.

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.

08 May 2014

Make the spheres always look spherical independently of axis scaling.

29 May 2014

Added transparency as optional argument

06 Jun 2014

Change demo figure

Contact us