colouring dots in scatter3 according z-value
61 ビュー (過去 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!