How to set wiskers and box in the boxplot?

19 views (last 30 days)
Fabian Moreno
Fabian Moreno on 8 Jul 2021
Commented: Fabian Moreno on 11 Jul 2021
Hello, I would like to set none line the outline border of the box , but it becomes black. If I remove the outline border, the wiskers also remove. So I try to change color of the outline border, but wiskers also change color. I would like leave the wiskers lines in black and the border with out the line, just with the fill color. Any help?
Here is my code.
grp = cell2mat(arrayfun(@(i){i*ones(numel(cuad_periodo{i}),1)},(1:numel(cuad_periodo))'));
boxplot(vertcat(cuad_periodo{:}),grp); set(gca,'fontsize',16);hold on
h = findobj(gca,'Tag','Box');
Box=get(get(gca,'children'),'children');set(Box,'Color',[0.4660, 0.6740, 0.1880]);
lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');set(lines, 'Color', 'k','linewidth',2);
for i=1:96
patch(get(h(i),'XData'),get(h(i),'YData'),'y','FaceAlpha',.9,'FaceColor',[0.4660, 0.6740, 0.1880],'LineStyle','none');
end
set(gca,'children',flipud(get(gca,'children')))
h=findobj(gca,'tag','Outliers');delete(h)
  3 Comments
Manan Jain
Manan Jain on 9 Jul 2021
Hi, Please share your solution, so others with similiar queries can get help. Thank you !
Fabian Moreno
Fabian Moreno on 11 Jul 2021
Sure!
grp = cell2mat(arrayfun(@(i){i*ones(numel(cuad_periodo{i}),1)},(1:numel(cuad_periodo))'));
boxplot(vertcat(cuad_periodo{:}),grp); set(gca,'fontsize',14);hold on
h = findobj(gca,'Tag','Box');
Box=get(get(gca,'children'),'children');set(Box,'Color',[0 0.4470 0.7410]);
% The next five lines are to set separately the boxplots objects.
lines = findobj(gca, 'type', 'line', 'Tag', 'Median');set(lines, 'Color', 'k','linewidth',2); % Adjusting the median line
up_adj = findobj(gca,'type', 'line', 'tag', 'Upper Whisker'); set(up_adj, 'Color', 'k','linewidth',1);% Setting the upper whiskers
low_adj= findobj(gca, 'type', 'line','tag', 'Lower Whisker'); set(low_adj, 'Color', 'k','linewidth',1);%Setting the lower whiskers
up = findobj(gca,'type', 'line', 'tag', 'Upper Adjacent Value'); set(up, 'Color', 'k','linewidth',1);%Setting the line betwwen percentile 75 and 95
low= findobj(gca, 'type', 'line','tag', 'Lower Adjacent Value'); set(low, 'Color', 'k','linewidth',1);%Setting the line betwwen percentile 25 and 5
for i=1:91
patch(get(h(i),'XData'),get(h(i),'YData'),'y','FaceAlpha',.9,'FaceColor',[0 0.4470 0.7410],'LineStyle','none');
end
set(gca,'children',flipud(get(gca,'children')))
h=findobj(gca,'tag','Outliers');delete(h)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!