直方图(`histogram`)
直方图(histogram)
03_统计与矩阵 5 张 MATLAB R2023b 100 mm 宽 @ 300 dpi
这个方法适合什么
单变量的频次分布,箱宽决定细节层次。适合:负荷分布、预测误差分布、温升分布、电压偏差分布。
电气场景
1 全日有功负荷分布

2 光伏预测误差分布

3 变压器绕组温升分布

4 母线电压偏差分布

5 馈线电流概率分布

代码
脚本 p3_stats_matrix.m 中对应 histogram 的一段,SEL 用于选择只跑某几个方法。
if any(SEL==1)
rng(101);
% ---- 1.1 全日有功负荷分布 ----
P = 3.5 + 3.0*lognrnd(0.42,0.26,1500,1);
bP = floor(min(P)) : 0.6 : ceil(max(P));
nP = histcounts(P,bP);
f = ml_fig(PP,100,80);
ax = axes('Parent',f,'Position',[0.175 0.190 0.770 0.755]);
histogram(ax,P,bP,'FaceColor',C(1,:),'EdgeColor','w','LineWidth',0.4, ...
'FaceAlpha',0.85);
xlabel(ml_tx('有功负荷 <i>P</i> / MW'));
ylabel(ml_tx('样本数 / 个'));
xlim(ax,[bP(1) bP(end)]); ylim(ax,[0 max(nP)*1.20]);
save_png(f,FIGD,'全日有功负荷分布');
% ---- 1.2 光伏预测误差分布 ----
e1 = 2.1*randn(900,1) + 0.5; % 晴天
e2 = 5.4*randn(900,1) - 0.8; % 多云
bE = -22:2:16;
p1 = histcounts(e1,bE,'Normalization','probability');
p2 = histcounts(e2,bE,'Normalization','probability');
f = ml_fig(PP,100,80);
ax = axes('Parent',f,'Position',[0.175 0.190 0.770 0.755]);
h1 = histogram(ax,e1,bE,'Normalization','probability', ...
'FaceColor',C(1,:),'EdgeColor','w','LineWidth',0.3,'FaceAlpha',0.75);
hold(ax,'on');
h2 = histogram(ax,e2,bE,'Normalization','probability', ...
'FaceColor',C(2,:),'EdgeColor','w','LineWidth',0.3,'FaceAlpha',0.55);
hold(ax,'off');
xlabel(ml_tx('预测误差 <i>e</i> / %'));
ylabel(ml_tx('概率'));
xlim(ax,[-23 17]); ylim(ax,[0 max([p1 p2])*1.32]); % 上方留图例空白带
lg = legend(ax,[h1 h2],ml_tx({'晴天','多云'}),'Location','northeast');
ml_style_legend(lg,PP);
save_png(f,FIGD,'光伏预测误差分布');
% ---- 1.3 变压器绕组温升分布 ----
dT = 34 + 7.5*randn(1200,1) + 4*exprnd(1.6,1200,1);
bD = floor(min(dT)/3)*3 : 3 : ceil(max(dT)/3)*3;
ndT = histcounts(dT,bD);
f = ml_fig(PP,100,80);
ax = axes('Parent',f,'Position',[0.175 0.190 0.770 0.755]);
histogram(ax,dT,bD,'FaceColor',C(3,:),'EdgeColor',[0.25 0.25 0.25], ...
'LineWidth',0.4,'FaceAlpha',0.80);
xlabel(ml_tx('绕组温升 Δ<i>T</i> / K'));
ylabel(ml_tx('样本数 / 个'));
xlim(ax,[bD(1) bD(end)]); ylim(ax,[0 max(ndT)*1.16]);
save_png(f,FIGD,'变压器绕组温升分布');
% ---- 1.4 各电压等级母线电压偏差 ----
u1 = 0.9*randn(800,1) + 0.4; % 10 kV
u2 = 1.3*randn(800,1) - 0.2; % 35 kV
u3 = 1.7*randn(800,1) + 0.9; % 110 kV
bU = -5:0.5:6;
maxU = max([histcounts(u1,bU) histcounts(u2,bU) histcounts(u3,bU)]);
f = ml_fig(PP,100,80);
ax = axes('Parent',f,'Position',[0.175 0.190 0.770 0.755]);
h1 = histogram(ax,u1,bU,'DisplayStyle','stairs','EdgeColor',C(1,:),'LineWidth',1.2);
hold(ax,'on');
h2 = histogram(ax,u2,bU,'DisplayStyle','stairs','EdgeColor',C(2,:),'LineWidth',1.2);
h3 = histogram(ax,u3,bU,'DisplayStyle','stairs','EdgeColor',C(3,:),'LineWidth',1.2);
hold(ax,'off');
xlabel(ml_tx('母线电压偏差 Δ<i>U</i> / %'));
ylabel(ml_tx('样本数 / 个'));
xlim(ax,[-5 6.5]); ylim(ax,[0 maxU*1.35]);
lg = legend(ax,[h1 h2 h3],ml_tx({'10 kV','35 kV','110 kV'}),'Location','northwest');
ml_style_legend(lg,PP);
save_png(f,FIGD,'母线电压偏差分布');
% ---- 1.5 馈线电流概率分布(横向)----
I = 120 + 34*randn(2000,1) + 55*abs(randn(2000,1));
bI = floor(min(I)/18)*18 : 18 : ceil(max(I)/18)*18;
pr = histcounts(I,bI,'Normalization','probability');
f = ml_fig(PP,100,80);
ax = axes('Parent',f,'Position',[0.175 0.190 0.770 0.755]);
histogram(ax,I,bI,'Normalization','probability', ...
'Orientation','horizontal','FaceColor',C(5,:), ...
'EdgeColor','w','LineWidth',0.4,'FaceAlpha',0.85);
ylabel(ml_tx('馈线电流 <i>I</i> / A'));
xlabel(ml_tx('概率'));
ylim(ax,[bI(1) bI(end)]); xlim(ax,[0 max(pr)*1.20]);
save_png(f,FIGD,'馈线电流概率分布');
end

浙公网安备 33010602011771号