Colorbar axis scaling

조회 수: 2 (최근 30일)
S K
S K 2011년 5월 18일
답변: Chad Greene 2014년 11월 10일
I want to print the dates from 1970 to 2010 as ticks of color bar. I have written following code and it shows the date from 1970 to 1978 only. Also I want all the color spectrum to appear in the colorbar but it is only showing the white color.
x=1:41;
clc;
t=x;
clf;
for i=1:41
plot(t(i),x(i),'--rs','MarkerSize',20,'Color',[i/41 (i*0.5)/41 (i*.1)/41]);
hold on;
end
Cbarlabels=['1970';'1971';'1972';'1973';'1974';'1975';'1976';'1977';'1978';'1979';'1980';'1981';'1982';'1983';'1984';'1985';'1986';'1987';'1988';'1989';'1990';'1991';'1992';'1993';'1994';'1995';'1996';'1997';'1998';'1999';'2000';'2001';'2002';'2003';'2004';'2005';'2006';'2007';'2008';'2009';'2010'];
colormap(jet(41));
h=colorbar('YTickLabel',Cbarlabels);
set(h,'YLim',[1970 2010]);

답변 (2개)

Doug Hull
Doug Hull 2011년 5월 18일
The key is to have the right number of elements in yTick:
x=1:41;
clc;
t=x;
clf;
for i=1:41
plot(t(i),x(i),'--rs','MarkerSize',20,'Color',[i/41 (i*0.5)/41 (i*.1)/41]);
hold on;
end
Cbarlabels=['1970';'1971';'1972';'1973';'1974';'1975';'1976';'1977';'1978';'1979';'1980';'1981';'1982';'1983';'1984';'1985';'1986';'1987';'1988';'1989';'1990';'1991';'1992';'1993';'1994';'1995';'1996';'1997';'1998';'1999';'2000';'2001';'2002';'2003';'2004';'2005';'2006';'2007';'2008';'2009';'2010'];
colormap(jet);
h=colorbar;
set(h,'YTick',linspace(1,64,41))
set(h,'YTickLabel',Cbarlabels);

Chad Greene
Chad Greene 2014년 11월 10일
cbdate can do this easily.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by