필터 지우기
필터 지우기

Surf coloring question: How CData works?

조회 수: 4 (최근 30일)
Csaba
Csaba 2019년 2월 17일
댓글: Csaba 2019년 2월 17일
I am trying to color different surf pictures. Surf by default colors the surface using the colorbar from minimum of z data up to maximum of z data, using the whole colorbar. I want this to override; color the z data according to the z scale. I have a demo program how I tried to do this:
figure(1);
x=1:50;
y=1:50;
z=rand(50,50);
hs=surf(x,y,z,...
'FaceColor','interp',...
'EdgeColor','none',...
'FaceLighting','gouraud');
abc=max(abs(zlim));
zlim([-abc,abc]);
colorbar;
mmin=min(min(z));
mmax=max(max(z));
hs.CData=(z-mmin)*(2*abc)/(mmax-mmin)-abc ;
view([1 0 0]);
If I run this program, I have a toolbar, saying that deep blue corresponds to -1, bright yellow corresponds to +1 (that is ok, that is what I wanted). The picture, however, is blue around the minimum value (around zero) and yellow at around +1. I would like to have "green" at zero, as it is on the colorbar.
What I am doing wrong???

채택된 답변

Rik
Rik 2019년 2월 17일
편집: Rik 2019년 2월 17일
This is where the caxis function is for. You can change the color axis to match your data to a desired part of your color bar.
figure(1);
x=1:50;
y=1:50;
z=rand(50,50);
hs=surf(x,y,z,...
'FaceColor','interp',...
'EdgeColor','none',...
'FaceLighting','gouraud');
abc=max(abs(zlim));
zlim([-abc,abc]);
colorbar;
view([1 0 0]);
caxis([-1 1])
  댓글 수: 1
Csaba
Csaba 2019년 2월 17일
Thanks, however,
caxis([-abc,abc]);
is the correct in my case.
So many commands!
I still do not understand why my method does not work?????

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by