19 回归分面图 lmplot

19 回归分面图 lmplot

这类图是什么

figure 级回归图,按变量分面比较斜率。

看什么:比较多组回归关系,斜率差异即敏感度差异。

5 个案例

19-1 按季节分面的气温—负荷回归:斜率差异直接可比

按季节分面的气温—负荷回归:斜率差异直接可比

19-2 按区域分面的电压—电流回归

按区域分面的电压—电流回归

19-3 按天气分面的辐照度—出力回归

按天气分面的辐照度—出力回归

19-4 按年份分面的负荷增长回归:截距上移即基础负荷增长

按年份分面的负荷增长回归:截距上移即基础负荷增长

19-5 按馈线分面的负载率—线损率回归

按馈线分面的负载率—线损率回归

代码

5 个函数取自 code/第四批_回归与矩阵261107.py。关键约束:不调用 sns.set_theme(),否则 font.family 被改成 Arial,中文会变方框;版式由 code/公共配置261107.py 里的 setup_cn_style() 与 save() / save_grid() 统一接管。

# 摘自 code/第四批_回归与矩阵261107.py

def lm_01():
    """按季节分面的气温—负荷回归:斜率差异直接可比。"""
    fig, ax = new_fig(left=0.19)
    fig.delaxes(ax)
    rng = np.random.default_rng(1901)
    rows = []
    for s, slope, base in [("春季", 6.2, 400), ("夏季", 11.5, 420)]:
        t = rng.normal(22 if s == "春季" else 31, 5.5, 130)
        rows.append(pd.DataFrame({"气温": t,
                                  "负荷": base + slope * (t - 12) + rng.normal(0, 45, 130),
                                  "季节": s}))
    df = pd.concat(rows, ignore_index=True)
    g = sns.lmplot(data=df, x="气温", y="负荷", col="季节", hue="季节",
                   palette=PALETTE3[:2], height=3.15, aspect=0.78,
                   scatter_kws={"s": 14, "edgecolor": "white"},
                   line_kws={"lw": 1.0}, legend=False)
    g.set_axis_labels("气温 " + IT["T"] + " / °C", "有功负荷 " + IT["P"] + " / kW")
    save_grid(g, "19_回归分面图", "19_回归分面图_按季节分面气温负荷",
              left=0.14, bottom=0.21, right=0.97, top=0.84)

def lm_02():
    """按区域分面的电压—电流回归。"""
    fig, ax = new_fig(left=0.19)
    fig.delaxes(ax)
    rng = np.random.default_rng(1902)
    rows = []
    for area, u0, k in [("城区", 10.20, 0.00082), ("农村", 10.05, 0.00142)]:
        i = rng.gamma(9, 30, 140)
        rows.append(pd.DataFrame({"电流": i, "电压": u0 - k * i + rng.normal(0, 0.04, 140),
                                  "区域": area}))
    df = pd.concat(rows, ignore_index=True)
    g = sns.lmplot(data=df, x="电流", y="电压", col="区域", hue="区域",
                   palette=PALETTE3[:2], height=3.15, aspect=0.78,
                   scatter_kws={"s": 13, "edgecolor": "white"},
                   line_kws={"lw": 1.0}, legend=False)
    g.set_axis_labels("负荷电流 " + IT["I"] + " / A", "母线电压 " + IT["U"] + " / kV")
    save_grid(g, "19_回归分面图", "19_回归分面图_按区域分面电压电流",
              left=0.14, bottom=0.21, right=0.97, top=0.84)

def lm_03():
    """按天气分面的辐照度—出力回归。"""
    fig, ax = new_fig(left=0.19)
    fig.delaxes(ax)
    rng = np.random.default_rng(1903)
    rows = []
    for w, k in [("晴天", 0.92), ("多云", 0.74)]:
        g0 = rng.uniform(0, 1000, 130)
        rows.append(pd.DataFrame({"辐照度": g0, "出力": k * g0 + rng.normal(0, 18, 130),
                                  "天气": w}))
    df = pd.concat(rows, ignore_index=True)
    g = sns.lmplot(data=df, x="辐照度", y="出力", col="天气", hue="天气",
                   palette=PALETTE3[:2], height=3.15, aspect=0.78,
                   scatter_kws={"s": 13, "edgecolor": "white"},
                   line_kws={"lw": 1.0}, legend=False)
    g.set_axis_labels("辐照度 " + IT["G"] + " / (W/m²)", "有功出力 " + IT["P"] + " / kW")
    save_grid(g, "19_回归分面图", "19_回归分面图_按天气分面辐照出力",
              left=0.14, bottom=0.21, right=0.97, top=0.84)

def lm_04():
    """按年份分面的负荷增长回归:截距上移即基础负荷增长。"""
    fig, ax = new_fig(left=0.19)
    fig.delaxes(ax)
    rng = np.random.default_rng(1904)
    rows = []
    for y, scale in [("2023 年", 1.0), ("2025 年", 1.16)]:
        t = rng.normal(26, 7, 130)
        rows.append(pd.DataFrame({"气温": t,
                                  "负荷": scale * (400 + 9.6 * (t - 12)) + rng.normal(0, 46, 130),
                                  "年份": y}))
    df = pd.concat(rows, ignore_index=True)
    g = sns.lmplot(data=df, x="气温", y="负荷", col="年份", hue="年份",
                   palette=PALETTE3[:2], height=3.15, aspect=0.78,
                   scatter_kws={"s": 13, "edgecolor": "white"},
                   line_kws={"lw": 1.0}, legend=False)
    g.set_axis_labels("气温 " + IT["T"] + " / °C", "有功负荷 " + IT["P"] + " / kW")
    save_grid(g, "19_回归分面图", "19_回归分面图_按年份分面负荷增长",
              left=0.14, bottom=0.21, right=0.97, top=0.84)

def lm_05():
    """按馈线分面的负载率—线损率回归。"""
    fig, ax = new_fig(left=0.19)
    fig.delaxes(ax)
    rng = np.random.default_rng(1905)
    rows = []
    for fd, k in [("L1", 4.2), ("L2", 5.8)]:
        b = rng.uniform(0.2, 1.1, 110)
        rows.append(pd.DataFrame({"负载率": b, "线损率": k * b ** 2 + rng.normal(0, 0.25, 110),
                                  "馈线": fd}))
    df = pd.concat(rows, ignore_index=True)
    g = sns.lmplot(data=df, x="负载率", y="线损率", col="馈线", hue="馈线",
                   palette=PALETTE3[:2], order=2, height=3.15, aspect=0.78,
                   scatter_kws={"s": 13, "edgecolor": "white"},
                   line_kws={"lw": 1.0}, legend=False)
    g.set_axis_labels("负载率 " + IT["beta"], "线损率 / %")
    save_grid(g, "19_回归分面图", "19_回归分面图_按馈线分面负载线损",
              left=0.14, bottom=0.21, right=0.97, top=0.84)

说明

  • axes 级图 1181×944 px;figure 级多轴图按内容取 1100~1470 px 宽。
  • 图内不放标题,图题由本文件的标题承担。
  • 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定。
posted @ 2026-11-08 08:32  小青蛙电气  阅读(3)  评论(0)    收藏  举报