MATLAB Boxplot如何在‘compact‘及‘filled‘模式下改变箱子宽度并隐藏箱型图的中位数线?

该文章展示了如何在MATLAB中创建并自定义箱线图,包括设置箱体颜色、宽度,异常点大小,以及调整线条宽度和颜色。同时,对不同数据集的箱线图进行了区别处理,增强了图形的可读性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

figure(1)
hold on
position1 = 1.1:7.1;
position2 = 1.4:7.4;
b1 = boxplot(peak_lowfs_mean,label,...  
                    'width',2,...
                    'Color',[1 0.2 0],...                                      %箱体边框及异常点颜色
                    'PlotStyle','compact',...
                    'position',position1,...
                    'MedianStyle','line',...
                    'Notch','off',...
                    'OutlierSize',2);
set(b1,'Linewidth',1.5);   
lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(lines, 'Color', 'none');
%改变第一组箱子的箱宽              
a = get(get(gca,'children'),'children');   % Get the handles of all the objects
t = get(a,'tag');                          % List the names of all the objects 
idx=strcmpi(t,'box');                      % Find Box objects
boxes=a(idx);                              % Get the children you need
set(boxes,'linewidth',10);                 % Set width

b2 = boxplot(peak_highfs_mean,label,...  
                    'width',2,...
                    'Color',[0 0.2 1],...                                      %箱体边框及异常点颜色
                    'PlotStyle','compact',...
                    'position',position2,...
                    'MedianStyle','line',...
                    'Notch','off',...
                    'OutlierSize',2);
set(b2,'Linewidth',1.5);                
lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');
set(lines, 'Color', 'none');
%改变第二个箱子的箱宽  
b = get(get(gca,'children'),'children');   % Get the handles of all the objects
b = b{1};                                  % 此时有两组箱子,只改变第二组即可
t = get(b,'tag');                          % List the names of all the objects 
idx=strcmpi(t,'box');                      % Find Box objects
boxes=b(idx);                              % Get the children you need
set(boxes,'linewidth',10);                 % Set width

xlim([0.5 8])
ylim([0.5 3.5])
xlabel('{\itf}_s','position',[195.3,-22.25,0],'fontsize',20)
% xlabel('{\itf}_s')
ylabel('Peak counts','fontsize',20)
set(gca, 'XTick',1.25:1:7.25, 'XTickLabel', {'(0,0.1)','(0.1,0.2)','(0.2,0.3)','(0.3,0.4)','(0.4,0.5)','(0.5,1)'},'fontsize',12);

box on
set(gca,'FontSize',12);
set(gca,'Linewidth',1.5);
h = figure(1);
set(h,'units','normalized','position',[0.2 0.1 0.35 0.35]);

修改之前的图:
在这里插入图片描述修改后:

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值