2 views (last 30 days)

Hello everyone,

I have to create a 3D visualization of some data that I have. I have 2 vectors that represent mean and standard deviation of my data. I have to plot them in a 3d graph in which each point of the graph contains a pair of (mean,sd) value, and for each pair I have to draw a cloured point. The colour depends on the values of the mean (ex: red=high value, blu=low value).

Thank you, cordially

Carlotta

Adam Danz
on 19 Feb 2020

Edited: Adam Danz
on 19 Feb 2020

Use scatter3() to create the 3D scatter plot and scale the colors based on a vector of mean values.

% Create 100x3 matrix of [x,y,z] coordinates

xyz = randi(1000,100,3);

% Create 100x1 vector of means

mu = rand(100,1).*5;

% Create 3D scatter plot, colorcode the values based on mu values

scatter3(xyz(:,1),xyz(:,2),xyz(:,3), 40, mu, 'filled')

xlabel('x')

ylabel('y')

zlabel('z')

% equate aspect ratio (if needed)

axis equal

% Add colorbar if desired

cb = colorbar();

title(cb, 'Means')

Mil Shastri
on 19 Feb 2020

Check out this video starting from 18:04 https://www.mathworks.com/videos/matlab-for-excel-users-81634.html

At 19:04, Adam defines the color of the points. He also shows how you can have MATLAB automatically generate code for the customizations.

Sky Sartorius
on 19 Feb 2020

Use a scatter plot and CData:

n = 100;

xData = 1:n; % Placeholder - I assume you have additional information about the data to locate it in 3D space.

meanData = rand(n,1);

stdData = randn(n,1).^2;

scatter(xData,meanData,'CData',stdData);

h = colorbar;

h.Label.String = 'Standard deviation'

ylabel('Mean')

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799550

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799550

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799560

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799560

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799571

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799571

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799588

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/506420-how-can-i-create-a-3d-plot-of-data-with-dots-of-different-color#comment_799588

Sign in to comment.