필터 지우기
필터 지우기

How to get a set aspect ratio of 4:3 on a figure?

조회 수: 46 (최근 30일)
HC98
HC98 2024년 2월 21일
답변: Jonas 2024년 2월 21일
I want to plot 2 things side by side but at a fixed aspect ratio of 4:3. Is there a way to do this?
  댓글 수: 2
Jonas
Jonas 2024년 2월 21일
do you want to be the subplot be 4:3 or the whoe figure?
look into pbaspect()
HC98
HC98 2024년 2월 21일
@Jonas Each subplot

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

답변 (2개)

Ramtej
Ramtej 2024년 2월 21일
Hi
You use "subplot" function to draw two figures side by side and set the aspect ratio of each figure by using "pbaspect".
x = linspace(0, 2*pi, 100);
y1 = sin(x);
y2 = cos(x);
figure;
% Plot the first subplot
subplot(1, 2, 1);
plot(x, y1);
title('Sine Wave');
pbaspect([4 3 1]);
% Plot the second subplot
subplot(1, 2, 2);
plot(x, y2);
title('Cosine Wave');
pbaspect([4 3 1]);
Refer to the below documentation for the detailed instrutctions on how to use "pbaspect" function.

Jonas
Jonas 2024년 2월 21일
you could use pbaspect on each subplot
figure;
ax1=subplot(2,1,1);
plot(rand(10,1));
ax2=subplot(2,1,2);
plot(rand(100,1));
% run on each axis
arrayfun(@(in) pbaspect(in,[4 3 1]),[ax1 ax2])
% instead of saving each axis, you could collect all of the current figure after creation:
f=figure;
subplot(2,1,1);
plot(rand(10,1));
subplot(2,1,2);
plot(rand(100,1));
% run on each axis
axs=findall(f,'type','axes');
arrayfun(@(in) pbaspect(in,[4 3 1]),axs)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by