How can I move a colorbar when using heat maps? (2017a)

14 views (last 30 days)
How can I move a colorbar when using heat maps? (2017a) I keep getting the error:
Error using matlab.graphics.chart.Chart/colorbar Output arguments are not supported when using colorbar with heatmap.
Using 2017a
subplot('Position',[0.16 0.065 0.762 0.11])
heatmap(p_index, s_num, inc_diff(s_num,:), 'ColorLimits', [real_min, real_max], 'GridVisible', 'off', 'CellLabelColor', 'none');
xlabel('Parameter')
set(colorbar,'Position',[0.9 0.1 0.07 0.8])

Accepted Answer

Walter Roberson
Walter Roberson on 8 Jun 2018
That does not appear to be possible.
heatmap() turns out to create a sort of axis object, and colorbar notices that its parent is a heatmap and refuses to do some things.
If you do
ax = gca; %then ax becomes the handle to the heatmap
axs = struct(ax); %and ignore the warning
cb = axs.Colorbar; %now you have a handle to the colorbar object
However, if you try to set cb.Position then that will fail: the colorbar is being controlled by a layout manager which will promptly get confused and error out.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!