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

12 visualizzazioni (ultimi 30 giorni)
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])

Risposta accettata

Walter Roberson
Walter Roberson il 8 Giu 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.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by