Colorbar axis scaling

17 次查看(过去 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 中查找有关 Red 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by