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!