Color scatter plot points based on value in another array

243 Ansichten (letzte 30 Tage)
Publius
Publius am 20 Feb. 2022
Kommentiert: Publius am 22 Feb. 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.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 20 Feb. 2022
Bearbeitet: Cris LaPierre am 20 Feb. 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 Kommentar
Publius
Publius am 22 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by