Size of subplots in figure is not the same
33 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Inti Vanmechelen
il 9 Feb 2022
Commentato: Adam Danz
il 9 Feb 2022
I have attached a figure in which I want to plot 13 subplots.
I have used
subplot(5,3,n)
to do so.
For some reason, matlab makes plot n°8 smaller than all the other plots.
Does anyone know why this happens or what would the most straightforward way to fix this?
Thanks!
6 Commenti
DGM
il 9 Feb 2022
Modificato: DGM
il 9 Feb 2022
Something must be different. The other plots don't have ylabels, and there's no title.
Without knowing what exactly happened, all I can say is to use the geometry of the neighboring axes to fix the errant one(s).
open BOXPLOTS.fig
hax = get(gcf,'children');
P0 = vertcat(hax.Position);
for k = 1:numel(hax)
hax(k).Position(3:4) = P0(5,3:4);
end
P1 = vertcat(hax.Position);
for k = 1:numel(hax)
hax(k).Position(1) = P0(k,1)-(P1(k,3)-P0(k,3));
end
That will just ignore the cause and simply resize all the axes to be the same size.
Risposta accettata
Adam Danz
il 9 Feb 2022
The cause of the problem is difficult to troubleshoot without having a reproducible example. Here are two workarounds.
Set PositionConstraint
I think this should fix the problem but since we don't have a reproducible example, I can't be sure. Set the PositionConstraint of the axes to innerposition before applying axis labels etc. As explained in the documentation, this will keep the inner axis position constant when adding labels etc.
figure()
ax = subplot(3,5,1); % <--------------------------use axis handles!
boxplot(ax, rand(5,6))
set(ax,'PositionConstraint','innerposition') % <---set PositionConstraint
hold(ax,'on') % <----------------------------------hold on
yt = get(ax, 'YTick');
axis([xlim 0 ceil(max(yt)*1.2)])
xt = get(ax, 'XTick');
% plot(ax, xt([1 2]), [1 1]*max(yt)*1.1, '-k', mean(xt([1 2])), max(yt)*1.15, '*k')
% plot(ax, xt([3 4]), [1 1]*max(yt)*1.1, '-k', mean(xt([3 4])), max(yt)*1.15, '*k')
hold(ax,'off')
xticklabels(ax,{'DCP RF','TD RF','DCP RGV','TD RGV','DCP RS','TD RS'});
% a = get(ax,'XTickLabel'); % <-----------------Redundant to the line above
% set(gca,'XTickLabel',a,'fontsize',8)
set(ax,'fontsize',8)
ylabel(ax,'Standard deviation (°)','FontSize',11);
title(ax,'Elevation plane');
Used TiledLayout
figure()
tlo = tiledlayout(3,5);
ax = nexttile(tlo);
boxplot(ax, rand(5,6))
% (...)
ax2 = nexttile(tlo);
boxplot(ax2, rand(5,6))
% (...) etc....
2 Commenti
Adam Danz
il 9 Feb 2022
If you're using a Matlab release prior to R2020a, then use ActivePositionProperty rather than PositionConstraint. Otherwise, if you share the error and would like to fix it, I can help. But it sounds like TiledLayout worked for you (in also controls the innerposition property).
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Axes Appearance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!