Rescaling colormap/colorbar

조회 수: 21 (최근 30일)
D
D 2011년 4월 8일
I am trying to create a heat map for some data that does not take on negative values. To make sure there was sufficient contrast in the heat map, I created a new color map, in which I appended rgb values corresponding to black to cover the negative values:
newmap = [zeros(256, 3); jet(256)]
The resulting heat map is very good, but when I display the color bar, it includes the parts I had colored black. Is there a way to rescale the color bar, so that negative values are omitted, or to somehow change the color map to get maximal contrast for the data I have?
I suppose I could rescale my data so that it took on negative values, but that would affect the values that showed up on the color bar.
Thank you.

채택된 답변

Sarah Wait Zaranek
Sarah Wait Zaranek 2011년 4월 12일
If you get a handle to the colorbar, then you can set the y limits of the colorbar axis. This will allow you to show only the colors you wish on your colorbar. See my sample code below.
newmap = [zeros(256, 3); jet(256)];
colormap(newmap)
surf(peaks(30))
h = colorbar;
set(h,'Ylim',[1 8])

추가 답변 (1개)

S K
S K 2011년 5월 18일
I am potting the curves that represent data from 1970 to 2010 in all the colors starting from blue and ending in red. Next to plot I want the colorbar to appear showing the dates from blue-1970 to red 2010. My code shows only the date from 1970 to 1978. and the color is white only. Help me in getting all the ticks and color in the colorbar.
{
x=1:41;
t=x;
A=colormap(jet(41));
for i=1:41
plot(t(i),x(i),'--rs','MarkerSize',20,'Color',A(i,:));
hold on;
end
dates=1970:2010;
colormap(jet(41));
h=colorbar('YTickLabel',num2str(dates'));
set(h,'YLim',[1970 2010]);
}
Thanks in advance.
  댓글 수: 1
Sarah Wait Zaranek
Sarah Wait Zaranek 2011년 5월 23일
You get to change the tick labels instead of the limits.
See code below:
mylabels = num2str((1970:5:2010)');
set(h,'YTickLabel',mylabels)

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

Community Treasure Hunt

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

Start Hunting!

Translated by