How can I add colors on my 3D scatter plot ?

116 visualizaciones (últimos 30 días)
Louis THOMAS
Louis THOMAS el 8 de En. de 2020
Editada: Adam Danz el 28 de Ag. de 2020
Hi,
I have three vectors (listeX, listeY, listeCycles). I want to plot using scatter3() function.
It results in this chart:
cycles.JPG
I would like to color in different colors the points on the vertical axis Z, according to their Z-coordinate.
For instance, having red for the bottom data, green for medium and blue for the data above.
Here is my code . Thank you very much !
figure
scatter3(listeX,listeY,listeCycles,'MarkerEdgeColor','k','MarkerFaceColor',[0 .75 .75])
xlabel('Temps ouverture minimum (s)');
ylabel('deadband (°)');
zlabel('Nombre de cycles sur projection 10 000s');

Respuesta aceptada

Adam Danz
Adam Danz el 8 de En. de 2020
Editada: Adam Danz el 28 de Ag. de 2020
Specify color from scatter3()
You can specify the color of each point when you call scatter3(X,Y,Z,S,C) or by using the property-value, scatter3(X,Y,Z,. . .,'MarkerFaceColor',C) where C is an n-by-3 matrix of RGB value, one row for each point.
Specify color using the scatter object handle
Alternatively, you can specify the color after plotting by setting the CData property as an n-by-3 matrix of RGB values.
h = scatter3(. . ., 'filled');
h.CData = C;
Creating the RGB matrix
One simple way to create the RGB color matrix is to use one of Matlab's colormaps and specify the number of points. This example uses jet and inputs the number of values in the first input to scatter3, X. See this list for other built-in colormaps.
C = jet(numel(X));
To add a colobar,
set(gca, 'colormap', C)
colorbar()
Full Demo
figure
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
h = scatter3(x,y,z,'filled','MarkerEdgeColor','k');
axis equal
box on
C = jet(numel(x));
h.CData = C
set(gca, 'colormap', C)
colorbar()
  5 comentarios
Dipali Ghodake
Dipali Ghodake el 28 de Ag. de 2020
How to show colormap to this plot?
Adam Danz
Adam Danz el 28 de Ag. de 2020
set(gca, 'Colormap', C)
colorbar()

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by