How to change the height of the subplots without changing x,y-positions and width?

27 views (last 30 days)
I have plotted three subplots in one figure which appeared in the upper side of the main figure window as shown. The bottom of the figure is almost empty. When I use position to set their heights, their x,y-postions and widths were also changed because position is a four-elements vector i.e. [left bottom width height]. How can I increase only the height of the subplots (not the whole figure) without changing other priorities so that the tile at the bottom became less obvious?

Accepted Answer

Walter Roberson
Walter Roberson on 22 Mar 2021
all_axes = reshape(get(gcf, 'type','axes'), 1, []);
for ax = all_axes
ax.Position(4) = 250; %or as appropriate
end
This will only change the height information without changing the lower left corner or the width.
I believe you will find it to be unsatisfactory. Positions are numbered from the bottom left corner and proceed upwards. When you increase the height without changing anything else, then they are left at the same anchor point but go even higher up... promptly running off the top. I would suggest to you that, contrary to your earlier thoughts, that you do want to change multiple position parameters. For example,
dh = 250; %or as appropriate
all_axes = reshape(get(gcf, 'type','axes'), 1, []);
for ax = all_axes
ax.Position(3:4) = ax.Position(3:4) + [-dh,dh];
end
This moves the lower limit further down the screen (closer to the bottom, which is 0) and at the same time adds an equal amount to the height, so that the top edge stays the same but the bottom gets lower.
  5 Comments
Walter Roberson
Walter Roberson on 3 Mar 2022
Maybe something like
all_axes = reshape(findobj(gcf, 'type','axes'), 1, []);
ax_pos = cell2mat(get(all_axes, 'Position'));
ax_y = ax_pos(:,2);
ax_h = ax_pos(:,4);
ax_maxy = ax_y + ax_h;
ax_pos(:,2) = 0.05 * min(ax_maxy);
ax_pos(:,4) = ax_h - ax_pos(:,2);
ax_pos_c = num2cell(ax_pos, 2);
set(all_axes, {'Position'}, ax_pos_c);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!