How can I create a 3D plot of data with dots of different color?

조회 수: 92 (최근 30일)
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
  댓글 수: 4
Adam Danz
Adam Danz 2020년 2월 19일
The question is still unclear. This is how I understand it so far. Please either confirm or correct the following steps or replace them completely with more descriptive ones.
  1. So, you have two nx1 (or 1xn) vectors: one for the means, one of the stds.
  2. And you have a nx3 (or 3xn) matrix of [x,y,z] coordinates.
  3. You want to create a scatter plot of the [x,y,z] coordinates in a 3D plot and color-code each point based on the mean value (the std values aren't used).

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 2월 19일
편집: Adam Danz 2020년 2월 19일
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')

추가 답변 (2개)

Mil Shastri
Mil Shastri 2020년 2월 19일
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
Sky Sartorius 2020년 2월 19일
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')

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by