Color scatter plot points based on value in another array

조회 수: 345 (최근 30일)
Publius
Publius 2022년 2월 20일
댓글: Publius 2022년 2월 22일
I have 3D data representing position and data in another array representing a field variable at each point. I want to scatter plot the 3D xyz data to maintain the shape of the object I want to represent while coloring each specific point based on the value of another variable.
For a simple example, say you have x, y, and z data for the points that make up the surface of an airplane and you know the pressure at each x, y, and z point. I want to scatter plot the xyz data to display the shape of the airplane (so that you can easily see the airplane shape), but color each individual point so that the highest pressure values are red and the lowest are blue (with a gradient in between). I'd also like to be able to display the gradient on a bar on the plot.
You can get close by either plotting the x y z data with scatter3, but you lose the pressure colors, or by plotting a 3D contour map, you lose the shape information. Some sort of intersection of these methods is what I'm looking for. Any help would be appreciated. Thank you.

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 2월 20일
편집: Cris LaPierre 2022년 2월 20일
Use the following syntax for scatter3
Your input C can be a vector the same length as your x,y,z data. See this example.
load patients
scatter3(Systolic,Diastolic,Weight,[],Diastolic,'filled')
colorbar
xlabel('Systolic')
ylabel('Diastolic')
zlabel('Weight')
colormap turbo
The syntax changes slightly if your data is stored in a table. See this example.
figure
tbl = readtable('patients.xls');
s = scatter3(tbl,'Systolic','Diastolic','Weight','filled', ...
'ColorVariable','Diastolic');
colorbar
colormap turbo
Just one comment about colormaps. The turbo colormap has a color scheme that is similar to the jet colormap, but the transitions between colors are more perceptually uniform. Use the turbo colormap for smoother transitions
  댓글 수: 1
Publius
Publius 2022년 2월 22일
Thanks so much! I had used the color vector to make gradients before (in the order that things were plotted) before, so I'm not sure why this didn't occur to me. Hope you have a nice day.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by