14 点线图 pointplot

14 点线图 pointplot

这类图是什么

按类别求均值并画置信区间,用点线连接。

看什么:看类别间的均值趋势与不确定性,比柱状更紧凑。

5 个案例

14-1 各时段负荷均值与置信区间:自动聚合

pointplot 自动按类别求均值并画 95% 置信区间,不必先 groupby 再手算,点与线的组合比柱状图更适合看"趋势 + 不确定性"。

各时段负荷均值与置信区间:自动聚合

14-2 三种方案的效率均值对比:误差棒即置信区间

三种方案的效率均值对比:误差棒即置信区间

14-3 各月负荷均值走势:月度趋势与波动范围

各月负荷均值走势:月度趋势与波动范围

14-4 两区域负荷率的分组点线:按季节对比

两区域负荷率的分组点线:按季节对比

14-5 不同负载率下的温升均值:直接看出限值交叉点

不同负载率下的温升均值:直接看出限值交叉点

代码

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

# 摘自 code/第三批_类别图261107.py

def pt_01():
    """各时段负荷均值与置信区间:自动聚合。

    pointplot 自动按类别求均值并画 95% 置信区间,不必先 groupby 再手算,
    点与线的组合比柱状图更适合看"趋势 + 不确定性"。
    """
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1401)
    rows = []
    for seg, mu in [("0-4", 380), ("4-8", 460), ("8-12", 640),
                    ("12-16", 590), ("16-20", 700), ("20-24", 440)]:
        rows.append(pd.DataFrame({"负荷": rng.normal(mu, 45, 120), "时段": seg}))
    df = pd.concat(rows, ignore_index=True)
    sns.pointplot(data=df, x="时段", y="负荷", color=C1, errorbar=("ci", 95),
                  markers="o", ms=4, lw=1.0, capsize=0.12, ax=ax)
    ax.set_xlabel("时段 / h")
    ax.set_ylabel("有功负荷 " + IT["P"] + " / kW")
    ax.set_ylim(300, 790)
    save(fig, "14_点线图", "14_点线图_分时段负荷均值")

def pt_02():
    """三种方案的效率均值对比:误差棒即置信区间。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1402)
    rows = []
    for p, mu, sd in [("原状", 0.842, 0.020), ("方案一", 0.881, 0.018),
                      ("方案二", 0.906, 0.016)]:
        rows.append(pd.DataFrame({"效率": rng.normal(mu, sd, 150), "方案": p}))
    df = pd.concat(rows, ignore_index=True)
    sns.pointplot(data=df, x="方案", y="效率", color=C1, errorbar=("ci", 95),
                  markers="s", ms=4, lw=1.0, capsize=0.12, ax=ax)
    ax.set_xlabel("降损方案")
    ax.set_ylabel("系统综合效率 " + IT["eta"])
    ax.set_ylim(0.80, 0.94)
    save(fig, "14_点线图", "14_点线图_各方案效率均值")

def pt_03():
    """各月负荷均值走势:月度趋势与波动范围。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1403)
    rows = []
    base = [470, 452, 486, 512, 548, 606, 636, 622, 566, 528, 492, 476]
    for i, mu in enumerate(base, 1):
        rows.append(pd.DataFrame({"负荷": rng.normal(mu, 42, 90), "月份": f"{i}"}))
    df = pd.concat(rows, ignore_index=True)
    sns.pointplot(data=df, x="月份", y="负荷", color=C3, errorbar=("ci", 95),
                  markers="o", ms=4, lw=1.0, capsize=0.10, ax=ax)
    ax.set_xlabel("月份")
    ax.set_ylabel("月均负荷 " + IT["P"] + " / kW")
    ax.set_ylim(400, 700)
    save(fig, "14_点线图", "14_点线图_各月负荷均值")

def pt_04():
    """两区域负荷率的分组点线:按季节对比。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1404)
    rows = []
    for area, off in [("A 区", 0.0), ("B 区", -0.06)]:
        for s, mu in [("春季", 0.72), ("夏季", 0.83), ("秋季", 0.77), ("冬季", 0.75)]:
            rows.append(pd.DataFrame({"负荷率": rng.normal(mu + off, 0.04, 100),
                                      "季节": s, "区域": area}))
    df = pd.concat(rows, ignore_index=True)
    sns.pointplot(data=df, x="季节", y="负荷率", hue="区域", palette=[C5, C1],
                  errorbar=("ci", 95), markers=["o", "s"], ms=4, lw=1.0,
                  capsize=0.10, ax=ax)
    ax.set_xlabel("季节")
    ax.set_ylabel("日负荷率")
    ax.set_ylim(0.62, 0.92)
    legend_in(ax, "upper left")
    save(fig, "14_点线图", "14_点线图_双区域负荷率")

def pt_05():
    """不同负载率下的温升均值:直接看出限值交叉点。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1405)
    rows = []
    for L in [0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]:
        d = rng.normal(28 + 26 * L ** 2, 2.2 + 1.0 * L, 90)
        rows.append(pd.DataFrame({"温升": d, "负载率": f"{L:.1f}"}))
    df = pd.concat(rows, ignore_index=True)
    sns.pointplot(data=df, x="负载率", y="温升", color=C1, errorbar=("ci", 95),
                  markers="o", ms=3.6, lw=1.0, capsize=0.10, 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, 80)
    save(fig, "14_点线图", "14_点线图_温升随负载率")

说明

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