MATLAB Answers


How to keep colorbar without changing the figure size?

Asked by Osama Tabbakh on 29 Apr 2019
Latest activity Commented on by Osama Tabbakh on 30 Apr 2019
I have 2 figures. One of them should be figured with colorbar and another one without. But they have the same scale. The problem is, that when I figured the colorbar with the first one the size of the figure will be changed. Any idea how I can fix this?


Sign in to comment.




1 Answer

Answer by Erivelton Gualter on 29 Apr 2019
 Accepted Answer

You can set the desired size of the figure. For example:
figure(1); % Figure 1 with out colorbar
% Get Position of the figure 1
pos = get(gcf, 'Position'); % gives x left, y bottom, width, height
x = pos(1); y = pos(2); w = pos(3); h = pos(4);
figure(2); % Figure 2 with colorbar
% Set Position with desired width w_new = w*1.1
set(gcf, 'Position', [x, y, w*1.1, h])
Then, you can adjust according to your wishes.

  1 Comment

Thank you very much Erivelton, but it still difficult because they will be not exactly identical. But It works thanks.

Sign in to comment.