How to give one x and y axis label when using tiled layout('flow')?

조회 수: 325 (최근 30일)
Brianna Miranda
Brianna Miranda 2022년 10월 4일
댓글: Cris LaPierre 2024년 3월 26일 13:15
I am using tiled layout('flow') to plot a series of 20 plots on one figure. I want to have just one x and one y label for the entire figure, but when I try using the following code I get a figure that plots every subplot over each other.
figure()
t=tiledlayout('flow');
autoCorr = zeros(ceil(length(dataSource)),N);
lag = zeros(ceil(length(dataSource)),N);
for ii=1:N
[autoCorr(:,ii),lag(:,ii)] = autocorrelation(dataSource(:,ii));
nexttile(t)
plot(lag(:,ii),autoCorr(:,ii))
end
title(t,'title')
xlabel(t,'xlabel')
ylabel(t,'ylabel')
When I use this code the plot works fine but I'm not sure how to add the x and y axis labels.
autoCorr = zeros(ceil(length(dataSource)),N);
lag = zeros(ceil(length(dataSource)),N);
figure()
tiledlayout('flow')
for ii=1:N
[autoCorr(:,ii),lag(:,ii)] = autocorrelation(dataSource(:,ii));
nexttile
plot(lag(:,ii),autoCorr(:,ii))
% xlim([100,fmax])
end

채택된 답변

Cris LaPierre
Cris LaPierre 2022년 10월 4일
Use the xlabel and ylabel functions with the first input being your tiled layout object. The code below is taken from this example.
t = tiledlayout(2,2,'TileSpacing','Compact');
% Tile 1
nexttile
plot(rand(1,20))
title('Sample 1')
% Tile 2
nexttile
plot(rand(1,20))
title('Sample 2')
% Tile 3
nexttile
plot(rand(1,20))
title('Sample 3')
% Tile 4
nexttile
plot(rand(1,20))
title(t,'Size vs. Distance')
xlabel(t,'Distance (mm)')
ylabel(t,'Size (mm)')
  댓글 수: 5
Cunxin Huang
Cunxin Huang 2024년 3월 26일 9:53
But what can I do under the case where I have a 4*6 figure and I want only the first and the second row share the same ylabel? Thank you
Cris LaPierre
Cris LaPierre 2024년 3월 26일 13:15
I don't know of a way to add a shared label to a subset of the plots. In this case, I suggest labeling each Y axis individually

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by