102visualizaciones (últimos 30días)
Mostrar comentarios más antiguos
Louis THOMAS el 8 de En. de 2020
Editada: Adam Danz el 28 de Ag. de 2020
Respuesta aceptada: Adam Danz
Abrir en MATLAB Online
Hi,
I have three vectors (listeX, listeY, listeCycles). I want to plot using scatter3() function.
It results in this chart:
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');
0 comentarios Mostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos
Mostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos
Iniciar sesión para comentar.
Iniciar sesión para responder a esta pregunta.
Respuesta aceptada
Adam Danz el 8 de En. de 2020
Editada: Adam Danz el 28 de Ag. de 2020
Abrir en MATLAB Online
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 Mostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Mostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Louis THOMAS el 9 de En. de 2020
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/499521-how-can-i-add-colors-on-my-3d-scatter-plot#comment_784719
Abrir en MATLAB Online
Thank you !
the problem now is that the command h.CData=C; does not have any impact on my chart colors ...
figure
C=jet(numel(listeX2));
h=scatter3(listeX2,listeY,listeCycles,'MarkerEdgeColor','k','MarkerFaceColor',[0 .75 .75]);
h.CData = C;
xlabel('Temps ouverture minimum (s)');
ylabel('deadband (°)');
zlabel('Nombre de cycles sur projection 10 000s');
view(-30,10)
Adam Danz el 9 de En. de 2020
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/499521-how-can-i-add-colors-on-my-3d-scatter-plot#comment_784721
Editada: Adam Danz el 9 de En. de 2020
Abrir en MATLAB Online
Try removing MarkerFaceColor and adding filled.
h=scatter3(listeX2,listeY,listeCycles,'filled','MarkerEdgeColor','k');
h.CData = C;
Here's a functional 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
C = jet(numel(x));
h.CData = C
Louis THOMAS el 9 de En. de 2020
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/499521-how-can-i-add-colors-on-my-3d-scatter-plot#comment_784736
Works perfectly thank you very much!
Dipali Ghodake el 28 de Ag. de 2020
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/499521-how-can-i-add-colors-on-my-3d-scatter-plot#comment_989393
How to show colormap to this plot?
Adam Danz el 28 de Ag. de 2020
Enlace directo a este comentario
https://la.mathworks.com/matlabcentral/answers/499521-how-can-i-add-colors-on-my-3d-scatter-plot#comment_989414
Abrir en MATLAB Online
set(gca, 'Colormap', C)
colorbar()
Iniciar sesión para comentar.
Más respuestas (0)
Iniciar sesión para responder a esta pregunta.
Ver también
Categorías
MATLABGraphicsFormatting and AnnotationColormaps
Más información sobre Colormaps en Help Center y File Exchange.
Etiquetas
- scatter3
- plot
- color
- cdata
- scatter
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Se ha producido un error
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia-Pacífico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Comuníquese con su oficina local