Specific values in colorbar
이전 댓글 표시
I am trying to plot a heatmap as the following:
data = [2 1 0 0 0 0 0 0 0 0;1 2 15 0 0 0 0 0 0 0];
colormap('hot');
imagesc(data);
colorbar;
But I want a colorbar with only the values in my data. I don't really need the "transitioning" ones. Is there a way to do so?
Thanks!
채택된 답변
추가 답변 (1개)
Walter Roberson
2016년 1월 11일
data_range = ceil(max(data(:))) - floor(min(data(:))) + 1;
imagesc(data);
colormap(hot(data_range));
colorbar();
댓글 수: 2
Arthur Brigatto
2016년 1월 15일
Walter Roberson
2016년 1월 15일
For MATLAB R2014a and earlier, colorbar() creates a new axes, which you can record the handle of and set() the YTick parameter of.
You would probably want to be setting the ticks at unique(data(:))
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!