Below's some code that generates a figure that has a colorbar with a custom label:
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]);
Notice that the colorbar
is still parula
(the default) and not gray
as I asked it politely to be.
The natural way to solve some graphical glitch like this is by "invalidating" the figure... Unfortunately, the popular commands drawnow
and refresh
, executed after the figure is at the shown state, do not remedy this situation.
It should be noted that exporting the figure results in the correct colors.
Question: Does anybody have an idea why this happens and how to fix it (preferably without workarounds / hacks)?
I'm running R2016b, on Win 7. As far as I know, this does not happen on Octave 4.0.3.
Several workarounds seem to solve this issue:
I have no idea why this happens though. My best guess is that JIT tries to execute these commands on multiple threads. Then, when
colormap
tries to change the colors of thecolorbar
, it encounters an object "locked" byylabel
, and as a result cannot perform its function. However the update "directive" does make its way into some event queue that execute when certain things happen to the figure.