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

137 次查看(过去 30 天)
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');

采纳的回答

Adam Danz
Adam Danz 2020-1-8
编辑:Adam Danz 2020-8-28
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by