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 中查找有关 Color and Styling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!