How to set y axis limit same for 2 subplots in a figure object?

조회 수: 107 (최근 30일)
I am creating a multiple figure object in a loop, I named it h. (h = figure) Each h contains two subplots. For both subplots in each h the yaxis limit needs to be same. For each h yaxis limit is different. How can I set yaxis limit for both subplots in each figure? Here is the sample structure of my code.
for feature = 1:numel(features)
h = figure;
for Tasktypedone = 1:2
subplot(1,2,Tasktypedone);
subplot(1,2,Tasktypedone);
end
maxY = 10; % maxY is generated dynamically
% set yLim = [0, maxY] for both subplots in h
end

채택된 답변

Voss
Voss 2022년 9월 22일
Store the axes objects returned from subplot(), and then set their YLim:
features = 99;
for feature = 1:numel(features)
h = figure;
ax = zeros(1,2); % ax: 1x2 vector of axes objects
for Tasktypedone = 1:2
ax(Tasktypedone) = subplot(1,2,Tasktypedone); % store the subplot axes
end
maxY = 10;
set(ax,'YLim',[0 maxY]); % set the YLim for both axes
end
You may also want to look into linkaxes:
  댓글 수: 1
Struggling in MATLAB
Struggling in MATLAB 2022년 9월 22일
Thank you! That's a great idea. Is there a workaround to work with the object h without storing the subplot axes. Something like:
h.yLim = [0 yMax];

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

추가 답변 (0개)

카테고리

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