How can I associate the markers of my SCATTER3 plot with a color map in MATLAB 7.10 (R2010a)?

2 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Aug 2010
To control how your SCATTER3 markers are colored you can make use of the CData property of your graphic object.
CData controls the color of markers. If you would like to map your points with a colormap you can use a vector with the same length of your XData and YData then the values in CData are linearly mapped to the colors in the current colormap.
Please consider the following code as an example:
%%Define data
[x,y,z] = sphere(16);
X = [x(:)*.5 x(:)*.75 x(:)];
Y = [y(:)*.5 y(:)*.75 y(:)];
Z = [z(:)*.5 z(:)*.75 z(:)];
%%Create Scatter3 plot with CDATA value Z
scatter3(X(:),Y(:),Z(:),'CData',Z(:))
colorbar
In this case the Z value has been used to define the colormap but you can consider any other different map you may like by inserting a different vector with the same size of X and Y.

More Answers (0)

Categories

Find more on Color and Styling in Help Center and File Exchange

Tags

Products


Release

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!