Size of subplots in figure is not the same
조회 수: 28 (최근 30일)
이전 댓글 표시
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
DGM
2022년 2월 9일
편집: DGM
2022년 2월 9일
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.
채택된 답변
Adam Danz
2022년 2월 9일
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
Adam Danz
2022년 2월 9일
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).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!