Drawing fancy box plots

조회 수: 90 (최근 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 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