箱型图颜色填充代码的出处:
how to fill boxes in Boxplot with different colors
data = rand(100, 4);
x = 1:4;
colors = rand(4, 3);
boxplot(data, x);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),colors(j,:),'FaceAlpha',.5);
end
上述代码复制自参考链接,以下是本人修改后的:
figure(1)
data = rand(100, 2);
hb = boxplot(data,...
'Color','k',... %箱体边框及异常点颜色
'symbol','.',... %异常点形状
'Notch','on',... %异常点形状
'OutlierSize',4,... %是否是凹口的形式展现箱线图,默认非凹口
'labels',{'Group A', 'Group B'});
set(hb,'LineWidth',1.5) %箱型图线宽
colors = [0.1 0.7 0.7;
1 0.4 0.6];
h = findobj(gca,'Tag','Box');
for j = 1:length(h)
patch(get(h(j),'XData'),get(h(j),'YData'),colors(j,:),'FaceAlpha',.5);%赋颜色填充箱型图内部
end
xlabel('X label')
ylabel('Y label')
ylim([0 1])
box on
set(gca,'Linewidth',1.5);
set(gca,'FontSize',16);
h = figure(1);
set(h,'units','normalized','position',[0.2 0.1 0.35 0.35]);
效果图如下:
如何隐藏中值线
h = findobj(gca,‘Tag’,‘Median’);
set(h,‘Visible’,‘off’);
参考链接:
论文常用图表三:盒图 Boxplot【MATLAB】
display mean instead of median in boxplot matlab