How to fix unallignment of box plot in subplot when using sgtitle?
显示 更早的评论
When I use the 'sgtitle' command to make a title for the subplot figure, becomes the first subplot unalligned with the others. Is there a way to fix this?
'G' is a 105 element long row-vector
...
noa = ones(1,5);
nob = repmat(2,1,5);
noc = repmat(4,1,5);
no = cat(2,noa,nob,noc);
figure(5)
sgtitle('Fracture Energy vs Height')
% Titles
tph = ('3Dd1s1 d1s1 d1s2 d1s4 d2s1 d2s2 d2s4');
tph = split(tph);
G_sub = 0;
for i = 1:length(G)
if rem(i,15)==0
G_sub = G(i-14:i);
subplot(2,4,i/15)
boxplot(G_sub,no)
title(tph(i/15))
xlabel('Height [mm]')
grid
end
end
Output:

Thank you
采纳的回答
更多回答(1 个)
Monica Roberts
2022-5-20
1 个投票
This looks like a bug. You should contact MATLAB support: https://servicerequest.mathworks.com/mysr/cp_case_new1?bug=true
They will want to know what version of MATLAB you are using, and what is the minimum number of lines you can cut back to replicate the issue (i.e. does it still happen without data? Without boxplot?)
In the meantime, some things you can try:
- What happens if you put sgtitle at the end of this code?
- If you have a more recent version of MATLAB you could try "tiledlayout" instead of "subplot" (introduced in R2019b). Then you can use "title" with the tiledlayout object instead of sgtitle.
- If "boxplot" is the issue, you could try the newer "boxchart" (introduced in R2020a)
类别
在 帮助中心 和 File Exchange 中查找有关 Power Converters 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
