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

23 views (last 30 days)

Show older comments

##### 1 Comment

### Accepted Answer

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
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);

### More Answers (0)

### See Also

### Community Treasure Hunt

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

Start Hunting!