colouring dots in scatter3 according z-value
60 次查看(过去 30 天)
显示 更早的评论
plot3 gives colours according to height above the xy-plane. Is that possible with scatter3 too?
0 个评论
采纳的回答
Star Strider
2017-9-18
It is relatively straightforward to do what you want:
x = rand(10, 1); % Create Data
y = rand(10, 1); % Create Data
z = rand(10, 1); % Create Data
zscaled = z*10; % May Be Necessary To Scale The Colour Vector
cn = ceil(max(zscaled)); % Number Of Colors (Scale AsAppropriate)
cm = colormap(jet(cn)); % Define Colormap
figure(2)
scatter3(x, y, z, [], cm(ceil(zscaled),:), 'filled')
grid on
4 个评论
Maria Zilidou
2022-3-26
what happens if x,y,z are matrices? for example x,y,z are 10x10 matrices. how do you asign colours according to the value of z using scatter3?
Star Strider
2022-3-26
I would create them as vectors using the (:) subscript notation:
scatter3(x(:), y(:), z(:), [], z(:))
or something similar and appropriate.
.
更多回答(2 个)
Weia Reinboud
2017-9-18
1 个评论
José-Luis
2017-9-18
You can specify the color as a linear function of z:
x = 1:10;
z = fliplr(x);
scatter3(x,x,z,2,z)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!