one common y label for the subplots

64 ビュー (過去 30 日間)
mehra
mehra 2021 年 10 月 14 日
編集済み: Cris LaPierre 2021 年 10 月 14 日
I am trying to remove the y labels in the inner plots of my subplot figures by using straightforward codes which I couldn't, here's my code,
here I used position for ylabel which didn't work
is there a short way for this?
for r=1:10
subplot(2,13,r)
plot(u_lat_con(:,r)./Uund,yler_D2,'r');
xlabel('$\overline{u}/U_0$','interpreter','latex')
% ylabel('$y/D$','interpreter','latex')
ylabel('$y/D$','position',[-1 8],'interpreter','latex')
title(sprintf('x/D=%.2f',xler_c(r)./D))
xlim([-0.3 1.3]);
ylim([0 3.1133]);
end
% ylabel('$y/D$','POSITION',[-1 8],'interpreter','latex')
for r=1:13
subplot(2,13,r+13)
plot(u_lat_w(:,r)./Uund,yler_D1,'b',u_lat_w(:,r)./Uund,-yler_D1,'b');
xlabel('$\overline{u}/U_0$','position',[4 7],'interpreter','latex')
% ylabel('$y/D$','interpreter','latex')
title(sprintf('x/D=%.2f',xler1(r)./D))
xlim([-0.3 1.3])
ylim([-3.5 3.5])
end

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 10 月 14 日
編集済み: Cris LaPierre 2021 年 10 月 14 日
If you use tiledlayout instead of subplot, you can add shared title and axis labels. See this example.
t = tiledlayout(2,2,'TileSpacing','Compact');
% Tile 1
nexttile
plot(rand(1,20))
% Tile 2
nexttile
plot(rand(1,20))
% Tile 3
nexttile
plot(rand(1,20))
% Tile 4
nexttile
plot(rand(1,20))
% Create shared title, xlabel and ylabel
title(t,'Size vs. Distance')
xlabel(t,'Distance (mm)')
ylabel(t,'Size (mm)')
  2 件のコメント
mehra
mehra 2021 年 10 月 14 日
I have some cases which doesn't have fixed m by n tiles,(2 rows with different columns in each row for example) so using subplot works better for me
Cris LaPierre
Cris LaPierre 2021 年 10 月 14 日
編集済み: Cris LaPierre 2021 年 10 月 14 日
If you can do it with subplot, you should be able to do it with tiledlayout. You can jump to a specific tile using the syntax nexttile(7). For example, if your grid is 3x3, that command will take you to the bottom left tile.
This is equivalent to subplot(3,3,7).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by