how to plot multiple graphs with same x-axis and y-axis?

31 ビュー (過去 30 日間)
bouchra turki
bouchra turki 2023 年 1 月 7 日
コメント済み: Matt J 2023 年 1 月 8 日
Hello
how can I plot multiple graphs in one figure with the same x-axis and y-axis, like in the following figure?
I 'm really needed this one.
Thank you very much.

回答 (2 件)

Matt J
Matt J 2023 年 1 月 7 日
編集済み: Matt J 2023 年 1 月 7 日
Using subaxis(), downloaded from here,
for i=1:3
subaxis(1,3,i,'SpacingHoriz',0);
plot(rand(1,5));
xlabel X
if i==1
ylabel Y
else
yticklabels([]);
end
end
  2 件のコメント
bouchra turki
bouchra turki 2023 年 1 月 8 日
移動済み: Matt J 2023 年 1 月 8 日
Thank you very much for your quick answers, but the both functions subaxis() and tiledlayout() didn't work in MATLAB2018a!
Matt J
Matt J 2023 年 1 月 8 日
Subaxis is about 20 years old. It wll definitely work in 2018a. My guess would be that you assumed it was a built-in Matlab command, and didn't download it rom the link I gave you.

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


Voss
Voss 2023 年 1 月 7 日
You can try something along these lines:
% create a tiledlayout for 3 plots, with no space between:
N_plots = 3;
t = tiledlayout(1,N_plots,'TileSpacing','none');
% create and store the three axes:
ax = zeros(1,N_plots);
for ii = 1:N_plots
ax(ii) = nexttile(t);
hold on
end
% link the x- and y-limits of the axes:
linkaxes(ax,'xy')
% plot some stuff in each axes:
plot(ax(1),-12:12,rand(1,25))
plot(ax(1),-8:8,rand(1,17))
plot(ax(2),-9:9,rand(1,19))
plot(ax(2),-5:5,rand(1,11))
plot(ax(3),-10:10,rand(1,21))
plot(ax(3),-7:7,rand(1,15))
% set the x-limits of the left axes (the others will be set to the same
% because they are linked by linkaxes):
set(ax(1),'XLim',[-14 14]);
% remove the y-tick labels except on the left axes:
set(ax(2:end),'YTickLabel',{});
% set the y-label of the left axes:
set(get(ax(1),'YLabel'),'String','y')
% set the x-labels of all axes:
xlbl = get(ax,'XLabel');
set([xlbl{:}],'String','x')

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by