フィルターのクリア

Producing the same-sized box plots for subfigures

21 ビュー (過去 30 日間)
yp78
yp78 2021 年 10 月 26 日
コメント済み: yp78 2021 年 10 月 26 日
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.

採用された回答

Scott MacKenzie
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

その他の回答 (1 件)

Cris LaPierre
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')
  1 件のコメント
yp78
yp78 2021 年 10 月 26 日
Thank you for the nice suggestions!
I oversimplified my question; I actually needed to label y-axes differently for each row. I will follow your suggestion in other occasions :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by