Replace colorbar values with labels and center the tick marks?

조회 수: 1 (최근 30일)
Dan
Dan 2012년 4월 5일
Hello, Is there a way to replace colorbar values with labels and center the tick marks? Here is an example:
data=randi(10,10,10);
pcolor(data);colormap(jet(10));colorbar
This displays the values 1-10 on the colorbar, but I want to replace those values with labels (i.e., strings) and have the tick marks centered in the middle of each color interval.
Any help would be appreciated. Thanks, Dan

채택된 답변

Image Analyst
Image Analyst 2012년 4월 5일
Did you look up the help on colorbar and see this code:
colorbar('YTickLabel',...
{'Freezing','Cold','Cool','Neutral',...
'Warm','Hot','Burning','Nuclear'})
Why do you want to use pcolor()? Are you aware that it displays only 9x9 "tiles" for your 10x10 array, and that the color it chooses is related to the slope between two adjacent numbers rather than the number itself directly? If that's what you want fine, but if not, use image() or imshow() instead.
  댓글 수: 1
Dan
Dan 2012년 4월 5일
Thank you Image Analyst! I was using colorbar('YTick'...) instead of colorbar('YTickLabel',...). Thanks for clearing that up.
I was not familiar with image(), but that seems to work just fine! I do need the color to be related directly to the number. Thanks again.
Dan

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by