Color scatter plot points based on value in another array

361 次查看(过去 30 天)
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