Axis scale on a subplot log graphics

36 vues (au cours des 30 derniers jours)
casotti clément
casotti clément le 29 Déc 2021
Commenté : casotti clément le 29 Déc 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
  1 commentaire
Chunru
Chunru le 29 Déc 2021
Use same "ylim" for each subplot.

Connectez-vous pour commenter.

Réponse acceptée

Dave B
Dave B le 29 Déc 2021
Modifié(e) : Dave B le 29 Déc 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
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 commentaire
casotti clément
casotti clément le 29 Déc 2021
Thank you very much !! It works :)

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by