Color scatter plot points based on value in another array
256 次查看(过去 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.
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!