Producing the same-sized box plots for subfigures
11 次查看(过去 30 天)
显示 更早的评论
I want to produce one figure consisting of 4 by 3 =12 subfigures in the same size, in which the figures in the first column only display the tile and y-axes labels. However, my current code produces a figure where the size of the figures in the first colum is different from the rest of columns.
How can I fix this?
% Just generating a random data to plot the box plots
% I referred to this link: https://ch.mathworks.com/help/stats/boxplot.html
x1 = rand(5,1);
x2 = rand(10,1);
x3 = rand(15,1);
x = [x1; x2; x3];
g1 = repmat({'One'},5,1);
g2 = repmat({'Two'},10,1);
g3 = repmat({'Three'},15,1);
g = [g1; g2; g3];
%%
for i=1:12
subplot(4,3,i)
boxplot(x,g)
if i < 4
title(label{j})
end
if mod(i,3)==1
ylabel('Data');
end
end
The output looks like this.
0 个评论
采纳的回答
Scott MacKenzie
2021-10-26
One approach is just to use a dummy y-axis label for the plots in the 2nd and 3rd columns:
if mod(i,3)==1
ylabel('Data');
else
ylabel(' '); % dummy y-axis label
end
0 个评论
更多回答(1 个)
Cris LaPierre
2021-10-26
Since your y-axis labels are the same for all plots, consider using a tiled layout. I also use the newer boxchart function, which has slightly different syntax.
% Just generating a random data to plot the box plots
% I referred to this link: https://ch.mathworks.com/help/stats/boxplot.html
x1 = rand(5,1);
x2 = rand(10,1);
x3 = rand(15,1);
x = [x1; x2; x3];
g1 = repmat({'One'},5,1);
g2 = repmat({'Two'},10,1);
g3 = repmat({'Three'},15,1);
g = [g1; g2; g3];
%%
t = tiledlayout(4,3);
for i=1:12
nexttile
boxchart(categorical(g),x)
end
ylabel(t,'Data')
title(t,'360d')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!