15 柱状图 barplot

15 柱状图 barplot

这类图是什么

柱高为均值,误差棒为置信区间,自动聚合。

看什么:类别间的平均值对比,不必先 groupby 再手算。

5 个案例

15-1 三种方案的效率柱状:柱高是均值,误差棒是 95% CI

三种方案的效率柱状:柱高是均值,误差棒是 95% CI

15-2 各馈线最大负载率柱状:与满载线对照

各馈线最大负载率柱状:与满载线对照

15-3 按季节分组的区域负荷率柱状对比

按季节分组的区域负荷率柱状对比

15-4 各设备容量柱状:横向对比

各设备容量柱状:横向对比

15-5 分时段线损率柱状:与考核值对照

分时段线损率柱状:与考核值对照

代码

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

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

def bp_01():
    """三种方案的效率柱状:柱高是均值,误差棒是 95% CI。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1501)
    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.barplot(data=df, x="方案", y="效率", hue="方案", palette=PALETTE3,
                width=0.58, linewidth=0.5, errorbar=("ci", 95), errwidth=0.9,
                capsize=0.10, legend=False, ax=ax)
    ax.set_xlabel("降损方案")
    ax.set_ylabel("系统综合效率 " + IT["eta"])
    ax.set_ylim(0.78, 0.94)
    save(fig, "15_柱状图", "15_柱状图_各方案效率")

def bp_02():
    """各馈线最大负载率柱状:与满载线对照。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1502)
    rows = []
    for fd, mu in [("城东", 86), ("城西", 72), ("城南", 94), ("城北", 61), ("新区", 103)]:
        rows.append(pd.DataFrame({"负载率": rng.normal(mu, 3.2, 60), "馈线": fd}))
    df = pd.concat(rows, ignore_index=True)
    sns.barplot(data=df, x="馈线", y="负载率", hue="馈线", palette=PALETTE5,
                width=0.58, linewidth=0.5, errorbar=("ci", 95), errwidth=0.9,
                capsize=0.10, legend=False, ax=ax)
    ax.axhline(100, color=C2, lw=0.8, ls="--")
    ax.set_xlabel("馈线")
    ax.set_ylabel("最大负载率 / %")
    ax.set_ylim(0, 118)
    save(fig, "15_柱状图", "15_柱状图_各馈线负载率")

def bp_03():
    """按季节分组的区域负荷率柱状对比。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1503)
    rows = []
    for area, off in [("A 区", 0.0), ("B 区", -0.05)]:
        for s, mu in [("春季", 0.72), ("夏季", 0.83), ("秋季", 0.77)]:
            rows.append(pd.DataFrame({"负荷率": rng.normal(mu + off, 0.035, 100),
                                      "季节": s, "区域": area}))
    df = pd.concat(rows, ignore_index=True)
    sns.barplot(data=df, x="季节", y="负荷率", hue="区域", palette=[C5, C1],
                width=0.6, linewidth=0.5, errorbar=("ci", 95), errwidth=0.9,
                capsize=0.08, ax=ax)
    ax.set_xlabel("季节")
    ax.set_ylabel("日负荷率")
    ax.set_ylim(0.60, 0.92)
    legend_in(ax, "upper left", ncol=2)
    save(fig, "15_柱状图", "15_柱状图_双区域负荷率")

def bp_04():
    """各设备容量柱状:横向对比。"""
    fig, ax = new_fig(left=0.24)
    rng = np.random.default_rng(1504)
    rows = []
    for d, mu in [("主变 T1", 50), ("主变 T2", 40), ("储能 PCS", 10),
                  ("SVG", 6), ("逆变器", 5)]:
        rows.append(pd.DataFrame({"容量": rng.normal(mu, mu * 0.02, 30), "设备": d}))
    df = pd.concat(rows, ignore_index=True)
    sns.barplot(data=df, y="设备", x="容量", hue="设备", palette=PALETTE5,
                width=0.56, linewidth=0.5, errorbar=None, legend=False, ax=ax)
    ax.set_xlabel("额定容量 " + IT["S"] + " / (MV·A)")
    ax.set_ylabel("设备")
    ax.set_xlim(0, 58)
    save(fig, "15_柱状图", "15_柱状图_各设备容量")

def bp_05():
    """分时段线损率柱状:与考核值对照。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(1505)
    rows = []
    for seg, mu in [("0-4", 3.8), ("4-8", 4.2), ("8-12", 5.4),
                    ("12-16", 5.0), ("16-20", 5.8)]:
        rows.append(pd.DataFrame({"线损率": rng.normal(mu, 0.22, 80), "时段": seg}))
    df = pd.concat(rows, ignore_index=True)
    sns.barplot(data=df, x="时段", y="线损率", hue="时段", palette=PALETTE5,
                width=0.58, linewidth=0.5, errorbar=("ci", 95), errwidth=0.9,
                capsize=0.10, legend=False, ax=ax)
    ax.axhline(5.0, color=C2, lw=0.8, ls="--")
    ax.set_xlabel("时段 / h")
    ax.set_ylabel("线损率 / %")
    ax.set_ylim(0, 6.8)
    save(fig, "15_柱状图", "15_柱状图_分时段线损率")

说明

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