How to change colorbar's color (in some particular value interval)?

Hi , I want to change colorbar's color in some particular value interval.
For example , I likes the jet colorbar , link is my figure, but I want to
let the value between -0.5~ 0.5 to become white color, how can I do this?
thank you much !!

 채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 2일
You need to create a new colormap that has the appropriate colors in the appropriate range.
It appears that you have your plot set up to automatically map your minimum data to the lowest color, and your maximum data to the highest color.
I estimate that the range you want to change is roughly 2/3 of the way to the highest color as your range looks like -4 to +2 .
So you need to use something like
newmap = jet; %starting map
ncol = size(newmap,1); %how big is it?
zpos = 1 + floor(2/3 * ncol); %2/3 of way through
newmap(zpos,:) = [1 1 1]; %set that position to white
colormap(newmap); %activate it

댓글 수: 3

Thanks a lot , it work!!
But is there any way to know the correspond value to each color in the colorbar?
Because I have many figure to plot, each have different scale, if I can find
out the value to color correspondence relationship , I can write a program
to automatic change color around zero value.
thank you!!!
newmap = jet(); %change as desired, e.g., flag(256)
minz = double(min(YourZ(:)));
if minz > 0
disp('Your range is all above 0, no change');
else
maxz = double(max(YourZ(:)));
if maxz < 0
disp('Your range is all below 0, no change');
else
ncol = size(newmap, 1);
zratio = (0 - minz) ./ (maxz - minz);
zpos = max( round(zratio * ncol), 1); %closest non-zero
newmap(zpos,:) = [1 1 1]; %set there to white
colormap(newmap); %activate it
end
end
thank you!!!!

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

추가 답변 (2개)

Amith Kamath
Amith Kamath 2013년 6월 2일

0 개 추천

You can manually change the colormap, using COLORMAPEDITOR:
Double click on the color markers below the spectrum displayed, and choose the color you want to display that range of data in, using the color picker.

카테고리

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

제품

질문:

2013년 6월 2일

답변:

2018년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by