Hi.
I have a 2D contour
contour(handles.Object,x,y,z,...)
where I set the colour map using an rgb matrix
b = (.23 .6 .8;...
.7 .8 .9;...
etc)
caxis([20 50]);
cbr = colormap(b)
colorbar
By default, the colorbar has seven ticks. What I want to do is create a colorbar in the range between 20 and 50 with a tick right at the bottom marking "20", one right at the top marking "50" and ticks marking 22, 24, 26, 28,... (steps of 2) inbetween.
If I type
set(cbr,'YTickLabel',{'20','22','24','26',[...],'50'})
the colormap only returns the first seven values in the positions of the initial five ticks.
Is there a way to manipulate the AMOUNT and POSITIONS of the ticks so that I can get a colorbar as described above?
Thanks!
Marc

 채택된 답변

Laurent
Laurent 2013년 9월 4일
편집: Laurent 2013년 9월 4일

5 개 추천

The 'YTick' property contains the locations of the ticks on the Y axis, so I guess that
set(cbr,'YTick',20:2:50)
should do the trick.

댓글 수: 2

Marc Jakobi
Marc Jakobi 2013년 9월 4일
Thanks. That did the trick.
Utsav
Utsav 2016년 5월 18일
Thanks it helped me a lot too

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

추가 답변 (1개)

Diana
Diana 2016년 11월 17일

0 개 추천

Is there any way to set the number of ticks? I mean whatever the values are, I want always 5 ticks in the colorbar.

댓글 수: 1

Marc Jakobi
Marc Jakobi 2016년 11월 17일
편집: Marc Jakobi 2016년 11월 17일
You can use linspace.
set(cbr, 'YTick', linspace(a, b, 5));
Where a is the lower tick and b the upper one.

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

카테고리

질문:

2013년 9월 4일

편집:

2016년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by