In MATLAB2017a when I use contourf and then specify the colorbar ticks manually, the end tick is not shown. The end tick corresponds to the largest value in the contour matrix. Doing something like thins:
S = floor(rand(20)*20)+1;
maxS = max(max(S)); %S is an integer matrix obtained from the previous code
tickStep = maxS/10;
contourf(S, 30)
bar = colorbar('XTick', [1,tickStep:tickStep:maxS]);
Is it a bug or is it a "feature"? How I can work around it?
Found a solution myself:
Basically it is related to the way contourf(S,30)
works. If we plot the values of the lines with contourf(S,30,'ShowText','on')
the highest value will be lower than maxS
. So the last tick is out of the range of possible values of the contour plot.
The best solution I came up with is to use contourf(S,linspace(1,maxS,30))
.Now the end tick is visible.