필터 지우기
필터 지우기

colouring dots in scatter3 according z-value

조회 수: 75 (최근 30일)
Weia Reinboud
Weia Reinboud 2017년 9월 18일
댓글: Star Strider 2022년 3월 26일
plot3 gives colours according to height above the xy-plane. Is that possible with scatter3 too?

채택된 답변

Star Strider
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
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
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
Weia Reinboud 2017년 9월 18일
Yes I'd read that. But that means every dot has that color C, not that colors vary by the value of z. Or am I wrong?
  댓글 수: 1
José-Luis
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)

댓글을 달려면 로그인하십시오.


Weia Reinboud
Weia Reinboud 2017년 9월 18일
Excellent, it works! It does not look as code I could ever having been able to find by myself. Thank you very much.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by