Label 14 names in colorbar

조회 수: 1 (최근 30일)
Jose
Jose 2012년 11월 5일
Hi everyone!
I need to put 14 labels in a colorbar in a surf. If I put 14 labels, only shows 7 labels (first 7).
The max number of labels I can put is 12, after that only put the half.
Can you help me?
Thanks!
  댓글 수: 1
Jan
Jan 2012년 11월 5일
편집: Jan 2012년 11월 5일
It is not clear, what code produces this problem. It would be helpful to create an answer, if you post the relevant part of your program to reduce the need to guess what "if I put 14 labels" exactly means.

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

답변 (4개)

Jan
Jan 2012년 11월 5일
편집: Jan 2012년 11월 5일
Tiny modification of Image Analysts code:
numberOfColors = 14;
myColorMap = rand(numberOfColors,3);
colormap(myColorMap);
for c = 1:numberOfColors % Make tick mark labels.
ca{c} = sprintf('Color #%d', c);
end
colorbar('YTickLabel', ca, 'YTick', 1.5:numberOfColors+0.5); % <== Changes
The num,ber of TickLabels must equal the number of Ticks.
  댓글 수: 1
Image Analyst
Image Analyst 2012년 11월 5일
Ah, so that's the trick! Thanks. I had thought it would just kind of uniformly distribute the labels, but a careful reading of the help shows you are right: " To substitute strings for numbers along a colorbar, you define a label for each tick location." And it looks like the very bottom of the colorbar is 1 and the bottom (not top) of the top color (#14 in our example) is 14, so that's why you had to add 0.5 to make the label be in the middle of each colored panel in the colorbar.

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


Image Analyst
Image Analyst 2012년 11월 5일
편집: Image Analyst 2012년 11월 5일
I can reproduce what you say, but I don't know how to solve it. I wasn't able to solve it in 5 minutes. I post my code here in case others want to take a shot at it:
numberOfColors = 14;
myColorMap = rand(numberOfColors,3);
colormap(myColorMap);
for c = 1 : numberOfColors % Make tick mark labels.
ca{c} = sprintf('Color #%d', c);
end
colorbar('YTickLabel', ca);
What's even weirder is that it seems to "wrap around" if you give less than some number. try putting in 4 or 6 into my code for numberOfColors.

Jonathan Epperl
Jonathan Epperl 2012년 11월 5일
Maybe I don't understand your question properly, but if I do, then you could do it like so:
surf(peaks)
c = colorbar;
set(c,'YTick',-6:8,'YTickLabel',num2str((-6:8)','%d'))
Now you got 15 labels on your colorbar, and since you have the handle of it, you can do all kinds of other stuff to it, too.

Jose
Jose 2012년 11월 6일
thanks to all! :D

카테고리

Help CenterFile Exchange에서 Colorbar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by