Colorbar axis scaling

3 visualizaciones (últimos 30 días)
S K
S K el 18 de Mayo de 2011
Respondida: Chad Greene el 10 de Nov. de 2014
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]);

Respuestas (2)

Doug Hull
Doug Hull el 18 de Mayo de 2011
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 el 10 de Nov. de 2014
cbdate can do this easily.

Categorías

Más información sobre Red en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by