Drawing fancy box plots

129 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by