|
参考教材《概率论与数理统计》第四版, 高等教育出版社 盛骤等编 P133
程序为:
clear,clc,close all
x = [102,110,117,118,122,123,132,150];
xs = sort(x);
%%% 绘制箱线图
n = length(x); p = [0.25,0.50,0.75]; xnp = zeros(size(p));
np = floor(n*p); r = n*p-np;
id = (r ==0); xnp(id) = (xs(np(id))+xs(np(id)+1))/2;
idn = (r~=0); xnp(idn) = xs(np(idn)+1);
xp = [xs(1),xnp,xs(n)];
figure('color',[1,1,1]);plot([xp(1:2)],[2,2],'b-','linewidth',1.5);hold on;
plot([xp(2),xp(4),xp(4),xp(2),xp(2)],[1,1,3,3,1],'b-','linewidth',1.5);
plot([xp(3),xp(3)],[1,3],'r-','linewidth',1.5);
plot(xp(4:5),[2,2],'b-','linewidth',1.5);
axis([xp(1)-10,xp(5)+10,0,4])
text(xp(1)-1,0.5,'Min','interpreter','latex');
text(xp(2)-1,0.5,'$$Q_1$$','interpreter','latex');
text(xp(3)-1,0.5,'$$M$$','interpreter','latex');
text(xp(4)-1,0.5,'$$Q_3$$','interpreter','latex');
text(xp(5)-1,0.5,'Max','interpreter','latex');
plot([xp(1)-10,xp,xp(5)+10],0.82*ones(1,7),'k-','linewidth',1.5)
plot(xp,0.82*ones(1,5),'k.','markersize',15)
axis off
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2025-1-8 01:57
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社