Axis scale on a subplot log graphics

조회 수: 41 (최근 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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by