向栏中添加标签时,颜色栏的颜色图不会更新

Colorbar's colormap not updating when also adding a label to the bar

下面的一些代码生成了一个带有自定义标签的颜色条的图形:

function q41269479
% Create an axes:
figure();
% Display an image:
hIm = imagesc(peaks);
% Adjust colormap and colorbar:
h = colorbar; colormap(gray);
ylabel(h, '\Delta', 'Rotation', 0, 'Units', 'Normalized', 'Position', [0.48 1.05]);

期望得到的

实际得到的

请注意,colorbar 仍然是 parula(默认值),而不是我礼貌地要求的 gray

解决像这样的一些图形故障的自然方法是 "invalidating" 图形...不幸的是,流行的命令 drawnowrefresh,在图形位于所示状态,不补救这种情况。

请注意,导出图形会产生正确的颜色。

问题:有没有人知道为什么会发生这种情况以及如何解决它(最好没有解决方法/技巧)?

我是 运行 R2016b,在 Win 7 上。据我所知,这不会发生在 Octave 4.0.3 上。

有几种解决方法似乎可以解决此问题:

% Solution 1: adding a pause/drawnow AFTER setting the colormap.
h = colorbar; colormap(gray); pause(eps);
% OR:
h = colorbar; colormap(gray); drawnow;

% Solution 2: change the figure size (e.g. maximize then minimize)
drawnow % Required to avoid Java errors
jFig = get(handle(gcf), 'JavaFrame'); 
jFig.setMaximized(true); pause(0.0001); jFig.setMaximized(false);

% Solution 3: add/remove datatip
hDataCursorMgr = datacursormode(gcf);
hDatatip = createDatatip(hDataCursorMgr,hIm); delete(hDatatip);

我不知道为什么会这样。我最好的猜测是 JIT 试图在多个线程上执行这些命令。然后,当 colormap 试图改变 colorbar 的颜色时,它遇到了 ylabel 的对象 "locked",因此无法执行其功能。然而,更新 "directive" 确实 进入了某个事件队列,该队列在图形发生某些事情时执行。