06 直方图 hist
用途
单一变量的分布形态,看双峰、偏态、离群段,是负荷与误差分析的第一步。
示例(5 张)
06-1 日负荷功率分布直方图(双峰:白天与晚高峰)

06-2 母线电压偏差分布(正态,含合格区间)

06-3 风电场风速 Weibull 分布与实测频次对比

06-4 光伏功率短期预测误差分布(叠加零均值参考线)

06-5 谐波电流幅值累积分布(按不同监测点分层)

代码
以下 5 个函数取自 code/第二批_分布图型261106.py,直接调用即可出图。版式(宋体 + Times、10 磅、刻度朝内四边、图内无标题、留白自检)由 code/公共配置261106.py 的 setup_cn_style() 与 save() 统一提供。
# 摘自 code/第二批_分布图型261106.py
def hist_01():
"""日负荷功率分布直方图(双峰:白天与晚高峰)。"""
fig, ax = new_fig()
rng = np.random.default_rng(101)
day = rng.normal(420, 68, 2600)
eve = rng.normal(640, 52, 1500)
data = np.clip(np.concatenate([day, eve]), 240, 820)
ax.hist(data, bins=36, color=C5, edgecolor="0.35", linewidth=0.5,
density=True, label="样本分布")
ax.hist(data, bins=36, histtype="step", color=C1, linewidth=1.0,
density=True, label="分布轮廓")
ax.set_xlabel("有功功率 " + IT["P"] + " / kW")
ax.set_ylabel("概率密度")
ax.set_xlim(240, 830)
legend(ax, "upper center", ncol=2)
save(fig, "06_直方", "06_直方_日负荷功率分布")
def hist_02():
"""母线电压偏差分布(正态,含合格区间)。"""
fig, ax = new_fig()
rng = np.random.default_rng(102)
d = rng.normal(0.6, 2.4, 3200)
n, bins, patches = ax.hist(d, bins=34, color=C5, edgecolor="0.35",
linewidth=0.5, density=True)
for ptc, left in zip(patches, bins[:-1]):
if left < -7 or left > 7:
ptc.set_facecolor(C3)
ax.axvline(7, color=C2, lw=0.8, ls="--", label="允许上限 +7%")
ax.axvline(-7, color=C2, lw=0.8, ls=":", label="允许下限 -7%")
ax.set_xlabel("电压偏差 / %")
ax.set_ylabel("概率密度")
ax.set_xlim(-9, 10)
legend(ax, "upper left", ncol=1)
save(fig, "06_直方", "06_直方_母线电压偏差分布")
def hist_03():
"""风电场风速 Weibull 分布与实测频次对比。"""
fig, ax = new_fig()
rng = np.random.default_rng(103)
k, lam = 2.1, 8.4
v = lam * rng.weibull(k, 6000)
ax.hist(v, bins=32, range=(0, 26), color=C5, edgecolor="0.35", linewidth=0.5,
density=True, label="实测频次")
xx = np.linspace(0.1, 26, 300)
pdf = (k / lam) * (xx / lam) ** (k - 1) * np.exp(-(xx / lam) ** k)
ax.plot(xx, pdf, color=C2, lw=1.0, label="Weibull 拟合")
ax.set_xlabel("风速 " + IT["v"] + " / (m/s)")
ax.set_ylabel("概率密度")
ax.set_xlim(0, 26)
legend(ax, "upper right", ncol=1)
save(fig, "06_直方", "06_直方_风速Weibull分布")
def hist_04():
"""光伏功率短期预测误差分布(叠加零均值参考线)。"""
fig, ax = new_fig()
rng = np.random.default_rng(104)
e = rng.laplace(0, 3.6, 4000)
e = e[(e > -18) & (e < 18)]
ax.hist(e, bins=40, color=C5, edgecolor="0.35", linewidth=0.5,
density=True, label="误差分布")
ax.axvline(0, color=C4, lw=0.7, label="零误差线")
ax.axvline(np.mean(e), color=C2, lw=0.9, ls="--",
label="均值 " + f"{np.mean(e):+.2f}")
ax.set_xlabel("预测误差 / %")
ax.set_ylabel("概率密度")
ax.set_xlim(-18, 18)
legend(ax, "upper left", ncol=1)
save(fig, "06_直方", "06_直方_光伏预测误差分布")
def hist_05():
"""谐波电流幅值累积分布(按不同监测点分层)。"""
fig, ax = new_fig()
rng = np.random.default_rng(105)
a = rng.gamma(2.4, 4.0, 2200)
b = rng.gamma(2.8, 3.2, 2200)
ax.hist(a, bins=30, color=C5, alpha=0.85, edgecolor="0.35", linewidth=0.4,
density=True, label="监测点 A")
ax.hist(b, bins=30, color=C3, alpha=0.55, edgecolor="0.35", linewidth=0.4,
density=True, label="监测点 B")
ax.set_xlabel("5 次谐波电流 " + IT["I"] + SUB["h"] + " / A")
ax.set_ylabel("概率密度")
ax.set_xlim(0, 40)
legend(ax, "upper right", ncol=1)
save(fig, "06_直方", "06_直方_谐波电流幅值分布")
说明
- 图片 1181×944 px(100 mm × 80 mm @ 300 dpi),三维图为 1181×1122 px。
- 图内不放标题,图题由本文件的标题承担。
- 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定,重跑结果一致。
浙公网安备 33010602011771号