MATLAB 颜色条结束刻度问题

MATLAB colorbar end tick issue

在 MATLAB2017a 中,当我使用 contourf 然后手动指定颜色条刻度时,未显示结束刻度。 结束刻度对应于等高线矩阵中的最大值。 做一些类似的事情:

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]);

这是错误还是 "feature"? 我该如何解决?

自己找到解决方案:

基本上与contourf(S,30)的工作方式有关。如果我们绘制带有 contourf(S,30,'ShowText','on') 的线的值,最高值将低于 maxS。所以最后一个刻度超出了等值线图的可能值范围。

我想到的最佳解决方案是使用 contourf(S,linspace(1,maxS,30))。现在可以看到结束标记了。