Drawing fancy box plots

73 ビュー (過去 30 日間)
omid zandi
omid zandi 2021 年 5 月 7 日
編集済み: Adam Danz 2021 年 12 月 2 日
Hi
is it possible to draw boxplots same as what i attached, in matlab? I have tried toolbox provided here : https://github.com/IoSR-Surrey/MatlabToolbox, but it does not seem to be able to do this. Does anyone has any suggestion?
Thanks in advance.

採用された回答

Adam Danz
Adam Danz 2021 年 5 月 7 日
編集済み: Adam Danz 2021 年 5 月 7 日
Here are examples using boxchart (requires Matlab r2020a) and boxplot with slightly different outcomes.
rng('default')
x = -pearsrnd(0,1,1,4,1000,8);
figure()
axes()
hold on
% Loop through each box in order to control color
for i = 1:size(x,2)
boxchart(repmat(i,size(x,1),1),x(:,i),'Orientation','horizontal');
end
legend(num2cell(char(double(64+(1:size(x,2))))),'Location','BestOutside')
box on
Demo using boxplot
boxplot() also has an orientation option but it does not fill the color of the boxplots (unless 'compact' style is used) and does not have a legend option.
rng('default')
x = -pearsrnd(0,1,1,4,1000,8);
groups = (1:size(x,2)) .* ones(size(x));
figure()
group = (1:size(x,2)).*ones(size(x,1),1);
boxplot(x(:),group(:),'Orientation','horizontal',...
'ColorGroup',lines(size(x,2)),'Symbol','o','OutlierSize',4);
  3 件のコメント
Adam Danz
Adam Danz 2021 年 5 月 7 日
I added another example to my answer using boxplot which existed long before boxchart but it doesn't have options to fill the boxplots nor does it easily support a legend.
Adam Danz
Adam Danz 2021 年 5 月 7 日
編集済み: Adam Danz 2021 年 12 月 2 日
Old version of example1
I'm storing this here for my own reference. It demonstrates some bugs in r2021a when using grouped data and horizontal orientation. Use the code from my answer above and ignore this.
Note: this has been fixed in R2021b.
Problem:
  1. XRuler and YRuler and not switched
  2. XRuler is categorical desipte using numeric inputs.
  3. XAxis limit isn't adjusted (axis tight fixes it)
rng('default')
x = -pearsrnd(0,1,1,4,1000,8);
groups = (1:size(x,2)) .* ones(size(x));
figure()
boxchart(x(:),'GroupByColor',groups(:),'Orientation','horizontal');
% axis tight % This fixes the xlim problem
legend(num2cell(char(double(64+(1:size(x,2))))),'Location','BestOutside')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by