Color scatter plot points based on value in another array

243 visualizaciones (últimos 30 días)
Publius
Publius el 20 de Feb. de 2022
Comentada: Publius el 22 de Feb. de 2022
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.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 20 de Feb. de 2022
Editada: Cris LaPierre el 20 de Feb. de 2022
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 comentario
Publius
Publius el 22 de Feb. de 2022
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by