フィルターのクリア

Colorbar axis scaling

3 ビュー (過去 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 Center および File ExchangeRed についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by