How to set subplots same size

조회 수: 191 (최근 30일)
Jurrien Plijter
Jurrien Plijter 2021년 7월 22일
댓글: Zhongzheng Wang 2022년 3월 28일
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.
clear all; clc;
dt = 0.01;
time = 0;
iter_limit = 1000;
iter = 0;
next_initial = [0 0]; % [angle [rad] , angular 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); hold on;
fig_animation=plot(0,0,'k',0, -1,'.k','MarkerSize',20);
axis equal;
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); hold on; grid on;
fig_timeplot=plot(0,0,'b',0,0,'r',0,0,'k');
hold on;
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]');
hold off;
  댓글 수: 1
Zhongzheng Wang
Zhongzheng Wang 2022년 3월 28일
HI! I am wondering if you solved this problem. I met the same issue.

댓글을 달려면 로그인하십시오.

채택된 답변

Yazan
Yazan 2021년 7월 22일
Because you are requesting to use the same length for the data units along each axis when you specified
axis equal
Matlab will not provide axes of the same width and height. A simple solution is to remove the line above.
  댓글 수: 6
Yazan
Yazan 2021년 7월 23일
편집: Yazan 2021년 7월 23일
Then a very simple solution is simply to increase the size of your figure, as you are doing manually by the mouse.
When you initiate your figure, use the following for example:
h = figure('Units', 'normalized', 'Position', [0.12 0.35 0.68 0.5]);
Generally, you can control the position, height, and width f the figure, and also axes. Read here and here. If you want to force two axes to have the same height and width, you can use the following:
% ax1 and ax2 are axes handles
ax1.Position(3:4) = ax2.Position(3:4);
Matlab however will override this command if this size of your figure does not allow having axes of the specified size.
Jurrien Plijter
Jurrien Plijter 2021년 7월 23일
yeah I tried the ax1.position stuff earlier, but that indeed didn't work. Using figure(...) does work however, thanks for that! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by