How to set subplots same size

179 views (last 30 days)
Jurrien Plijter
Jurrien Plijter on 22 Jul 2021
Hi all,
I would like to get my subplots the same size. It now defaults to the first picture below, but I would like to have it as in the second picture (created by manually sizing the figure). How to modify my code? Thanks for the help. The search function did not answer my question.
clearall; clc;
dt = 0.01;
time = 0;
iter_limit = 1000;
iter = 0;
next_initial = [0 0];%(角(rad)gular velocity [rad/sec]];
ode45_check_initial = next_initial;
torque = 0;
torque_setting = 2;
x1_save=[];
x2_save=[];
time_save=[];
torque_save=[];
h=figure(1);
subplot(1,2,1); holdon;
fig_animation=plot(0,0,'k',0, -1,'.k','MarkerSize',20);
axisequal;
xlim([-1.5 1.5]);
ylim([-1.5 1.5]);
xlabel('x [m]');
ylabel('y [m]');
fig_rectangle=rectangle('Position',[-0.05 -0.05 0.1 0.1],'FaceColor','k');
subplot(1,2,2); holdon; gridon;
fig_timeplot=plot(0,0,'b',0,0,'r',0,0,'k');
holdon;
xlim([ 0 iter_limit*dt]);
ylim([-1.5*pi 1.5*pi]);
xlabel('time [s]');
ylabel('amplitude [-]');
legend('angle [rad]','angular velocity [rad/s]','applied torque [Nm]');
holdoff;
1 Comment
Zhongzheng Wang
Zhongzheng Wang on 28 Mar 2022
HI! I am wondering if you solved this problem. I met the same issue.

Sign in to comment.

Accepted Answer

Yazan
Yazan on 22 Jul 2021
Because you are requesting to use the same length for the data units along each axis when you specified
axisequal
Matlab will not provide axes of the same width and height. A simple solution is to remove the line above.
6 Comments
Jurrien Plijter
Jurrien Plijter on 23 Jul 2021
yeah I tried the ax1.position stuff earlier, but that indeed didn't work. Using figure(...) does work however, thanks for that! :)

Sign in to comment.

More Answers (0)

s manbetx 845


Release

R2018b

Community Treasure Hunt

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

Start Hunting!