07 地毯图 rugplot
这类图是什么
把每个样本画成一根短竖线,常与密度图叠加。
看什么:看样本落点与聚集区,检查密度曲线外推区是否有真实支撑。
5 个案例
07-1 母线电压采样点的地毯图:每个样本一根竖线

07-2 三组样本落点的地毯图:密集处成带状

07-3 负荷密度叠加地毯图:每根竖线是一个小时样本
地毯图单独看信息有限,叠在密度曲线下沿就能看出样本在哪些区间扎堆,以及曲线外推区(尾部)是否有真实支撑。

07-4 两测点电压采样对比:地毯图并排看偏置

07-5 故障时刻在地毯图上的聚集:看出高发时段

代码
5 个函数取自 code/第二批_分布图261107.py。关键约束:不调用 sns.set_theme(),否则 font.family 被改成 Arial,中文会变方框;版式由 code/公共配置261107.py 里的 setup_cn_style() 与 save() / save_grid() 统一接管。
# 摘自 code/第二批_分布图261107.py
def rg_01():
"""母线电压采样点的地毯图:每个样本一根竖线。"""
fig, ax = new_fig(left=0.19, bottom=0.21)
rng = np.random.default_rng(701)
u = rng.normal(10.02, 0.14, 220)
sns.rugplot(x=u, color=C1, height=0.42, lw=0.7, ax=ax)
ax.axvline(9.30, color=C2, lw=0.8, ls="--")
ax.axvline(10.70, color=C2, lw=0.8, ls=":")
ax.set_yticks([])
ax.set_xlabel("母线电压 " + IT["U"] + " / kV")
ax.set_ylabel("样本")
ax.set_xlim(9.35, 10.70)
save(fig, "07_地毯图", "07_地毯图_母线电压采样")
def rg_02():
"""三组样本落点的地毯图:密集处成带状。"""
fig, ax = new_fig(left=0.19, bottom=0.21)
rng = np.random.default_rng(702)
rows = []
for seg, mu in [("峰段", 690), ("平段", 520), ("谷段", 360)]:
for v in rng.normal(mu, 55, 120):
rows.append((seg, v))
df = pd.DataFrame(rows, columns=["时段", "负荷"])
for i, (seg, color) in enumerate(zip(["谷段", "平段", "峰段"], PALETTE3)):
d = df.loc[df["时段"] == seg, "负荷"]
ax.plot(d, np.full(len(d), i) + rng.normal(0, 0.055, len(d)), "|",
color=color, ms=8, mew=0.8)
ax.set_yticks([0, 1, 2])
ax.set_yticklabels(["谷段", "平段", "峰段"])
ax.set_ylim(-0.6, 2.6)
ax.set_xlabel("有功负荷 " + IT["P"] + " / kW")
ax.set_ylabel("时段")
ax.set_xlim(150, 900)
save(fig, "07_地毯图", "07_地毯图_分时段负荷落点")
def rg_03():
"""负荷密度叠加地毯图:每根竖线是一个小时样本。
地毯图单独看信息有限,叠在密度曲线下沿就能看出样本在哪些区间扎堆,
以及曲线外推区(尾部)是否有真实支撑。
"""
fig, ax = new_fig(left=0.19, bottom=0.21)
rng = np.random.default_rng(703)
d = rng.normal(520, 78, 180)
sns.kdeplot(x=d, fill=True, color=C5, alpha=0.45, lw=1.0, ax=ax)
sns.rugplot(x=d, color=C1, height=0.10, lw=0.6, ax=ax)
ax.set_xlabel("有功负荷 " + IT["P"] + " / kW")
ax.set_ylabel("概率密度")
ax.set_xlim(240, 820)
save(fig, "07_地毯图", "07_地毯图_密度叠加落点")
def rg_04():
"""两测点电压采样对比:地毯图并排看偏置。"""
fig, ax = new_fig(left=0.19, bottom=0.21)
rng = np.random.default_rng(704)
a = rng.normal(10.10, 0.10, 150)
b = rng.normal(9.96, 0.15, 150)
sns.rugplot(x=a, color=C1, height=0.34, lw=0.7, ax=ax)
sns.rugplot(x=b, color=C3, height=-0.34, lw=0.7, ax=ax)
ax.axhline(0, color=C4, lw=0.5)
ax.set_yticks([])
ax.set_xlabel("母线电压 " + IT["U"] + " / kV")
ax.set_ylabel("上方 Ⅰ 段 / 下方 Ⅲ 段")
ax.set_xlim(9.45, 10.45)
ax.set_ylim(-0.6, 0.6)
save(fig, "07_地毯图", "07_地毯图_双测点电压对比")
def rg_05():
"""故障时刻在地毯图上的聚集:看出高发时段。"""
fig, ax = new_fig(left=0.19, bottom=0.21)
rng = np.random.default_rng(705)
peak = rng.normal(17, 2.4, 60)
other = rng.uniform(0, 24, 55)
h = np.concatenate([peak, other])
sns.rugplot(x=h, color=C3, height=0.55, lw=0.8, ax=ax)
ax.set_yticks([])
ax.set_xlabel("故障发生时刻 " + IT["t"] + " / h")
ax.set_ylabel("样本")
ax.set_xlim(0, 24)
save(fig, "07_地毯图", "07_地毯图_故障时刻聚集")
说明
- axes 级图 1181×944 px;figure 级多轴图按内容取 1100~1470 px 宽。
- 图内不放标题,图题由本文件的标题承担。
- 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定。
浙公网安备 33010602011771号