31 局部放大 inset
31 局部放大 inset
用途
主图看全局、子图看细节,用于故障瞬间、电压跌落。
示例(5 张)
31-1 日负荷曲线的局部放大(午间谷段)

31-2 谐波频谱的局部放大(3~7 次)

31-3 短路故障电流波形的局部放大(故障起始段)

31-4 母线电压曲线的局部放大(电压跌落段)

31-5 光伏出力曲线的局部放大(云遮波动段)

代码
以下 5 个函数取自 code/第五批_版式与结构261107.py,直接调用即可出图。样式(宋体 + Times、10 磅、刻度朝内四边、留白自检)由 code/公共配置261107.py 的 setup_cn_style() 和 save() 统一提供,本节不再重复。
# 摘自 code/第五批_版式与结构261107.py
def ins_01():
"""日负荷曲线的局部放大(午间谷段)。"""
fig, ax = new_fig()
rng = np.random.default_rng(3101)
t = np.arange(0, 24.01, 0.25)
p = 480 + 170 * np.exp(-((t - 10) / 3.4) ** 2) + 210 * np.exp(-((t - 16) / 3.0) ** 2)
p += rng.normal(0, 8, t.size)
ax.plot(t, p, color=C1, lw=1.0, label="实测负荷")
ax.set_xlabel("时间 " + IT["t"] + " / h")
ax.set_ylabel("有功负荷 " + IT["P"] + " / kW")
ax.set_xlim(0, 24)
ax.set_ylim(420, 760)
axi = ax.inset_axes([0.56, 0.56, 0.40, 0.36])
axi.plot(t, p, color=C1, lw=1.0)
axi.set_xlim(11.5, 13.5)
axi.set_ylim(630, 700)
axi.tick_params(direction="in", labelsize=FS - 3, length=2, width=0.5)
for s in axi.spines.values():
s.set_linewidth(0.5)
ax.add_patch(Rectangle((11.5, 630), 2.0, 70, fill=False,
edgecolor="0.35", linewidth=0.6))
save(fig, "31_局部放大", "31_局部放大_负荷曲线局部放大")
def ins_02():
"""谐波频谱的局部放大(3~7 次)。"""
fig, ax = new_fig()
h = np.arange(1, 26)
a = 120 / h ** 1.05
a[2], a[4], a[6] = 30, 40, 18
ax.bar(h * 50, a, width=22, color=C5, edgecolor="0.35", linewidth=0.4)
ax.set_xlabel("频率 " + IT["f"] + " / Hz")
ax.set_ylabel("幅值 " + IT["I"] + SUB["h"] + " / A")
ax.set_xlim(0, 1300)
axi = ax.inset_axes([0.52, 0.50, 0.44, 0.42])
axi.bar(h * 50, a, width=22, color=C1, edgecolor="0.35", linewidth=0.4)
axi.set_xlim(120, 380)
axi.set_ylim(0, 46)
axi.tick_params(direction="in", labelsize=FS - 3, length=2, width=0.5)
for s in axi.spines.values():
s.set_linewidth(0.5)
ax.add_patch(Rectangle((120, 0), 260, 46, fill=False,
edgecolor="0.35", linewidth=0.6))
save(fig, "31_局部放大", "31_局部放大_谐波频谱局部放大")
def ins_03():
"""短路故障电流波形的局部放大(故障起始段)。"""
fig, ax = new_fig()
t = np.linspace(0, 100, 2000)
base = 380 * np.sin(2 * np.pi * 50 * t / 1000)
sig = base.copy()
m = t > 45
sig[m] = 1050 * np.sin(2 * np.pi * 50 * t[m] / 1000 - 1.0) * np.exp(-(t[m] - 45) / 60)
ax.plot(t, sig, color=C1, lw=0.9)
ax.axvline(45, color=C4, lw=0.5, ls=":")
ax.set_xlabel("时间 " + IT["t"] + " / ms")
ax.set_ylabel("相电流 " + IT["I"] + " / A")
ax.set_xlim(0, 100)
axi = ax.inset_axes([0.52, 0.55, 0.44, 0.38])
axi.plot(t, sig, color=C1, lw=0.9)
axi.set_xlim(40, 52)
axi.set_ylim(-900, 700)
axi.tick_params(direction="in", labelsize=FS - 3, length=2, width=0.5)
for s in axi.spines.values():
s.set_linewidth(0.5)
ax.add_patch(Rectangle((40, -900), 12, 1600, fill=False,
edgecolor="0.35", linewidth=0.6))
save(fig, "31_局部放大", "31_局部放大_故障电流局部放大")
def ins_04():
"""母线电压曲线的局部放大(电压跌落段)。"""
fig, ax = new_fig()
rng = np.random.default_rng(3104)
t = np.arange(0, 24.01, 0.05)
u = 10.15 + 0.12 * np.sin((t - 8) / 24 * 2 * np.pi) + rng.normal(0, 0.008, t.size)
u[(t > 14.2) & (t < 14.8)] -= 0.28
ax.plot(t, u, color=C1, lw=0.9)
ax.set_xlabel("时间 " + IT["t"] + " / h")
ax.set_ylabel("母线电压 " + IT["U"] + " / kV")
ax.set_xlim(0, 24)
ax.set_ylim(9.94, 10.32)
axi = ax.inset_axes([0.55, 0.56, 0.40, 0.34])
axi.plot(t, u, color=C1, lw=1.1)
axi.set_xlim(13.8, 15.2)
axi.set_ylim(9.96, 10.10)
axi.tick_params(direction="in", labelsize=FS - 3, length=2, width=0.5)
for s in axi.spines.values():
s.set_linewidth(0.5)
ax.add_patch(Rectangle((13.8, 9.96), 1.4, 0.14, fill=False,
edgecolor="0.35", linewidth=0.6))
save(fig, "31_局部放大", "31_局部放大_电压跌落局部放大")
def ins_05():
"""光伏出力曲线的局部放大(云遮波动段)。"""
fig, ax = new_fig()
rng = np.random.default_rng(3105)
t = np.arange(6, 19.01, 0.05)
p = 850 * np.sin((t - 6) / 13 * np.pi) ** 1.3
p *= 1 - 0.45 * np.exp(-((t - 11.5) / 0.5) ** 2) * (np.sin(t * 9) > 0.2)
p += rng.normal(0, 9, t.size)
ax.plot(t, p, color=C3, lw=0.9)
ax.set_xlabel("时间 " + IT["t"] + " / h")
ax.set_ylabel("有功出力 " + IT["P"] + " / kW")
ax.set_xlim(6, 19)
axi = ax.inset_axes([0.50, 0.56, 0.45, 0.34])
axi.plot(t, p, color=C3, lw=1.1)
axi.set_xlim(10.6, 12.4)
axi.set_ylim(200, 900)
axi.tick_params(direction="in", labelsize=FS - 3, length=2, width=0.5)
for s in axi.spines.values():
s.set_linewidth(0.5)
ax.add_patch(Rectangle((10.6, 200), 1.8, 700, fill=False,
edgecolor="0.35", linewidth=0.6))
save(fig, "31_局部放大", "31_局部放大_光伏出力局部放大")
说明
- 图片尺寸 1181×944 px(100 mm × 80 mm @ 300 dpi),三维图为 1181×1122 px。
- 图内不放标题,图题由本文件的二级/三级标题承担。
- 数据为贴近广东实际量级的仿真算例,随机种子固定,重跑结果一致。

浙公网安备 33010602011771号