# Axis scale on a subplot log graphics

13 views (last 30 days)
casotti clément on 29 Dec 2021
Commented: casotti clément on 29 Dec 2021
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
Chunru on 29 Dec 2021
Use same "ylim" for each subplot.

Dave B on 29 Dec 2021
Edited: Dave B on 29 Dec 2021
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
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
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))]);
casotti clément on 29 Dec 2021
Thank you very much !! It works :)

### Categories

Find more on Subplots in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by