how to draw a 3d plot with different color?

Hi
I want to assign different color to the specific values in a 3D plot. for example: I have x=[1;2;4;3] y=[1;2;3;4] z=[0.1;0.2;0.3;0.4]
for z>=0.2 scatter3(x,y,z,'b','.') for z=<0.2 scatter3(x,y,z,'g','.')?
thanks

 채택된 답변

Rik
Rik 2018년 1월 31일

1 개 추천

Logical indexing is your answer:
scatter3(x(z>0.2),y(z>0.2),z(z>0.2),'b.')
hold on
scatter3(x(z=<0.2),y(z=<0.2),z(z=<0.2),'g.')

댓글 수: 4

farfar
farfar 2018년 1월 31일
Thanks !
farfar
farfar 2018년 1월 31일
is there a way that I can have a color bar in the plot to say z<0.2 in green and more than 0.2 is blue ?
Rik
Rik 2018년 1월 31일
You could hack a colorbar to do something like that, but it won't be pretty. (set the tick property to 0.2 and use caxis)
color = repmat('b', size(z));
color(z<0.2) = 'g';
pointsize = 20;
scatter(x, y, pointsize, color);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2018년 1월 31일

댓글:

2018년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by