Axis scale on a subplot log graphics
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
casotti clément
el 29 de Dic. de 2021
Comentada: casotti clément
el 29 de Dic. de 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 comentario
Respuesta aceptada
Dave B
el 29 de Dic. de 2021
Editada: Dave B
el 29 de Dic. de 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))]);
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!