Axis scale on a subplot log graphics

36 ビュー (過去 30 日間)
casotti clément
casotti clément 2021 年 12 月 29 日
コメント済み: casotti clément 2021 年 12 月 29 日
Hello,
I need to have a subplot of three log with the same axis scale and square axis. I only have square axis but the y scale is different for each subplot. I want to have exactly the same scale for the three plot. I already tried axis equal but it didn't work with axis square.
here is what I get
clement
  1 件のコメント
Chunru
Chunru 2021 年 12 月 29 日
Use same "ylim" for each subplot.

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

採用された回答

Dave B
Dave B 2021 年 12 月 29 日
編集済み: Dave B 2021 年 12 月 29 日
When you want to match the axis limits, a helpful trick is to store the handles to each axes so that you can later query/set the limits.
There are a few options to make the limits match, perhaps the easiest is to use linkaxes, which is made for this job and will keep the limits synchronized even if you later change them:
ax(1)=subplot(1,3,1);plot(1:3);axis square
ax(2)=subplot(1,3,2);plot(1:4);axis square
ax(3)=subplot(1,3,3);plot(1:5);axis square
linkaxes(ax)
This turns out to be easier if you use tiledlayout/nexttile to make your subplots because then the axes are children of the layout:
figure
t=tiledlayout(1,3);
nexttile;plot(1:3);axis square
nexttile;plot(1:4);axis square
nexttile;plot(1:5);axis square
linkaxes(t.Children)
If you don't want to use linkaxes for some reason, you can set the limits manually:
figure
t=tiledlayout(1,3);
nexttile;plot(1:3);axis square
nexttile;plot(1:4);axis square
nexttile;plot(1:5);axis square
xlims=cell2mat(xlim(t.Children));
ylims=cell2mat(ylim(t.Children));
xlim(t.Children, [min(xlims(:,1)) max(xlims(:,2))]);
ylim(t.Children, [min(ylims(:,1)) max(ylims(:,2))]);
  1 件のコメント
casotti clément
casotti clément 2021 年 12 月 29 日
Thank you very much !! It works :)

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by