您可以通过修改图形对象的属性(而不是修改函数本身)来更改boxplot
显示数据/分位数的方式。
这是一段代码,它将修改用于蓝框的分位数(最初,蓝框对应于.25和.75分位数,并将变为.1和.9)。上部/下部晶须的底部会相应地改变。请注意,晶须的尖端没有改变(它们仍然对应于四分位间距的1.5倍)。就像我们改变基本部分一样,你可以改变胡须的提示。
%%% load some data
load carsmall
MPG = MPG(ismember(Origin,'USA','rows'));
Origin = Origin(ismember(Origin,'USA','rows'),:)
Origin(isnan(MPG),:) = [];
MPG (isnan(MPG),:) = [];
%%% quantile calculation
q = quantile(MPG,[0.1 0.25 0.75 0.9]);
q10 = q(1);
q25 = q(2);
q75 = q(3);
q90 = q(4);
%%% boxplot the data
figure('Color','w');
subplot(1,2,1);
boxplot(MPG,Origin);
title('original boxplot with quartile', 'FontSize', 14, 'FontWeight', 'b', 'Color', 'r');
set(gca, 'FontSize', 14);
subplot(1,2,2);
h = boxplot(MPG,Origin) %define the handles of boxplot
title('modified boxplot with [.1 .9] quantiles', 'FontSize', 14, 'FontWeight', 'b', 'Color', 'r');
set(gca, 'FontSize', 14);
%%% modify the figure properties (set the YData property)
%h(5,1) correspond the blue box
%h(1,1) correspond the upper whisker
%h(2,1) correspond the lower whisker
set(h(5,1), 'YData', [q10 q90 q90 q10 q10]);% blue box
upWhisker = get(h(1,1), 'YData');
set(h(1,1), 'YData', [q90 upWhisker(2)])
dwWhisker = get(h(2,1), 'YData');
set(h(2,1), 'YData', [ dwWhisker(1) q10])
%%% all of the boxplot properties are here
for ii = 1:7
ii
get(h(ii,1))
end
这里是结果。
每当我修改功能附带MATLAB,我做它的一个拷贝,并用“我的”前缀它。因此,我的修改过的函数在新安装时不会被覆盖。我建议你也这样做,并重新使用修改的2012a版本。 – Jonas
如果您确实想要修改2012b版本,则应修复2106行开始的子函数computeBoxIndices。 – Jonas
谢谢。我不想修改R2012b版本,但是R2010b。我设法修改的那个是R2009a的文件。但我会试着按照乔纳斯的建议重复使用这一个,我会让你注意到的。 – Gnesson