13 增强箱线图 boxenplot
13 增强箱线图 boxenplot
这类图是什么
逐级变宽的信封表示多个分位点,专为大样本设计。
看什么:大样本时尾部形状比普通箱线清楚,适合判断长尾超限。
5 个案例
13-1 大样本温升的增强箱线:比普通箱线多画 7 个分位点
boxenplot 用逐级变宽的"信封"表示更多分位数,样本上万时尾部的形状比普通箱线(只有 4 个分位)清楚得多,适合判断是否存在长尾超限。

13-2 万级负荷样本的增强箱线:看尾部有多厚

13-3 电压偏差的大样本分布:尾部越限程度

13-4 谐波幅值的大样本增强箱线

13-5 故障修复时长的长尾分布:增强箱线最适合这种偏态数据

代码
5 个函数取自 code/第三批_类别图261107.py。关键约束:不调用 sns.set_theme(),否则 font.family 被改成 Arial,中文会变方框;版式由 code/公共配置261107.py 里的 setup_cn_style() 与 save() / save_grid() 统一接管。
# 摘自 code/第三批_类别图261107.py
def bn_01():
"""大样本温升的增强箱线:比普通箱线多画 7 个分位点。
boxenplot 用逐级变宽的"信封"表示更多分位数,样本上万时尾部的形状
比普通箱线(只有 4 个分位)清楚得多,适合判断是否存在长尾超限。
"""
fig, ax = new_fig(left=0.20)
rng = np.random.default_rng(1301)
rows = []
for L, mu in [(0.6, 38), (0.8, 45), (1.0, 54), (1.2, 66)]:
d = rng.lognormal(np.log(mu), 0.14, 4000)
rows.append(pd.DataFrame({"温升": d, "负载率": f"{L:.1f}"}))
df = pd.concat(rows, ignore_index=True)
sns.boxenplot(data=df, x="负载率", y="温升", hue="负载率", palette=PALETTE4,
width=0.62, linewidth=0.5, legend=False, ax=ax)
ax.axhline(65, color=C2, lw=0.9, ls="--")
ax.set_xlabel("负载率 " + IT["beta"])
ax.set_ylabel("顶层油温升 " + IT["T"] + " / K")
ax.set_ylim(25, 100)
save(fig, "13_增强箱线图", "13_增强箱线图_温升长尾")
def bn_02():
"""万级负荷样本的增强箱线:看尾部有多厚。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(1302)
rows = []
for seg, mu in [("谷段", 360), ("平段", 520), ("峰段", 690)]:
rows.append(pd.DataFrame({"负荷": rng.lognormal(np.log(mu), 0.18, 5000),
"时段": seg}))
df = pd.concat(rows, ignore_index=True)
sns.boxenplot(data=df, x="时段", y="负荷", hue="时段", palette=PALETTE3,
width=0.6, linewidth=0.5, legend=False, ax=ax)
ax.set_xlabel("时段")
ax.set_ylabel("有功负荷 " + IT["P"] + " / kW")
ax.set_ylim(150, 1150)
save(fig, "13_增强箱线图", "13_增强箱线图_负荷尾部")
def bn_03():
"""电压偏差的大样本分布:尾部越限程度。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(1303)
rows = []
for area, mu, sd in [("城区", 0.4, 1.8), ("郊区", 1.4, 2.6), ("农村", 2.8, 3.6)]:
rows.append(pd.DataFrame({"偏差": rng.normal(mu, sd, 6000), "区域": area}))
df = pd.concat(rows, ignore_index=True)
sns.boxenplot(data=df, x="区域", y="偏差", hue="区域", palette=PALETTE3,
width=0.6, linewidth=0.5, legend=False, ax=ax)
ax.axhline(7, color=C2, lw=0.8, ls="--")
ax.axhline(-7, color=C2, lw=0.8, ls=":")
ax.set_xlabel("供电区域")
ax.set_ylabel("电压偏差 / %")
ax.set_ylim(-12, 16)
save(fig, "13_增强箱线图", "13_增强箱线图_电压偏差尾部")
def bn_04():
"""谐波幅值的大样本增强箱线。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(1304)
rows = []
for h, k in [("3 次", 2.2), ("5 次", 2.8), ("7 次", 3.6), ("9 次", 5.0)]:
rows.append(pd.DataFrame({"幅值": rng.gamma(k, 30 / k, 5000), "次数": h}))
df = pd.concat(rows, ignore_index=True)
sns.boxenplot(data=df, x="次数", y="幅值", hue="次数", palette=PALETTE4,
width=0.6, linewidth=0.5, legend=False, ax=ax)
ax.set_xlabel("谐波次数 " + IT["h"])
ax.set_ylabel("谐波电流 " + IT["I"] + SUB["h"] + " / A")
ax.set_ylim(0, 70)
save(fig, "13_增强箱线图", "13_增强箱线图_谐波幅值")
def bn_05():
"""故障修复时长的长尾分布:增强箱线最适合这种偏态数据。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(1305)
rows = []
for kind, mu, sd in [("计划检修", 3.2, 0.5), ("故障抢修", 4.8, 0.9)]:
rows.append(pd.DataFrame({"时长": rng.lognormal(mu, sd, 4000), "类型": kind}))
df = pd.concat(rows, ignore_index=True)
sns.boxenplot(data=df, x="类型", y="时长", hue="类型", palette=[C5, C3],
width=0.55, linewidth=0.5, legend=False, ax=ax)
ax.set_xlabel("作业类型")
ax.set_ylabel("修复时长 " + IT["t"] + " / h")
ax.set_ylim(0, 130)
save(fig, "13_增强箱线图", "13_增强箱线图_修复时长长尾")
说明
- axes 级图 1181×944 px;figure 级多轴图按内容取 1100~1470 px 宽。
- 图内不放标题,图题由本文件的标题承担。
- 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定。

浙公网安备 33010602011771号