The ability for the colorbar to be aware of the axes' CDataMapping property is not available in MATLAB.
To work around this issue, the YTick and YTickLabel properties of the colorbar can be set manually based on the lenght of the colormap. Given a plot generated by the following code:
s = surf(peaks);
set(s,'CDataMapping','direct');
cb = colorbar('location','EastOutside');
The colorbar properties can be modified as follows:
ylimits = get(cb, 'YLim');
set(cb, 'YTick', linspace(ylimits(1), ylimits(2), 9));
set(cb, 'YTickLabel', {'< 0', '8', '16', '24', '32', '40', '48', '56', '> 64'});
Best Answer