04 条形图 barh

用途

类别名称较长时改用横向,如馈线名、设备名,避免 x 轴标签挤成一团。

示例(5 张)

04-1 各馈线最大负载率

各馈线最大负载率

04-2 各次谐波电流幅值(对数横轴)

各次谐波电流幅值(对数横轴)

04-3 各节点电压偏差百分数

各节点电压偏差百分数

04-4 主要电气设备额定容量

主要电气设备额定容量

04-5 四种储能配置方案的年化费用构成对比(堆叠条形)

四种储能配置方案的年化费用构成对比(堆叠条形)

代码

以下 5 个函数取自 code/第一批_基础图型261106.py,直接调用即可出图。版式(宋体 + Times、10 磅、刻度朝内四边、图内无标题、留白自检)由 code/公共配置261106.py 的 setup_cn_style() 与 save() 统一提供。

# 摘自 code/第一批_基础图型261106.py

def barh_01():
    """各馈线最大负载率。"""
    fig, ax = new_fig(left=0.24)
    f = ["城东", "城西", "城南", "城北", "开发区", "新区"]
    r = [86, 72, 94, 61, 103, 78]
    cols = [C2 if v > 100 else C1 for v in r]
    bars = ax.barh(range(len(f)), r, height=0.58, color=cols, edgecolor="0.35",
                   linewidth=0.5)
    ax.axvline(100, color=C4, lw=0.6, ls=":", label="满载线")
    for b, v in zip(bars, r):
        ax.text(v + 1.5, b.get_y() + b.get_height() / 2, f"{v}", va="center",
                fontsize=FS - 2)
    ax.set_yticks(range(len(f)))
    ax.set_yticklabels(f)
    ax.set_ylabel("馈线")
    ax.set_xlabel("最大负载率 / %")
    ax.set_xlim(0, 118)
    legend(ax, "lower right", ncol=1)
    save(fig, "04_条形", "04_条形_各馈线最大负载率")

def barh_02():
    """各次谐波电流幅值(对数横轴)。"""
    fig, ax = new_fig(left=0.20)
    h = ["2", "3", "4", "5", "6", "7", "9", "11", "13"]
    a = [4.2, 38.6, 2.1, 26.4, 1.3, 15.8, 6.2, 3.4, 1.8]
    bars = ax.barh(range(len(h)), a, height=0.6, color=C5, edgecolor="0.35",
                   linewidth=0.5)
    for i in (1, 3):
        bars[i].set_color(C1)
    for b, v in zip(bars, a):
        ax.text(v * 1.08, b.get_y() + b.get_height() / 2, f"{v:g}", va="center",
                fontsize=FS - 2)
    ax.set_xscale("log")
    ax.set_xlim(0.8, 90)
    ax.set_yticks(range(len(h)))
    ax.set_yticklabels(h)
    ax.invert_yaxis()
    ax.set_ylabel("谐波次数 " + IT["h"])
    ax.set_xlabel("谐波电流 " + IT["I"] + SUB["h"] + " / A")
    save(fig, "04_条形", "04_条形_谐波电流幅值")

def barh_03():
    """各节点电压偏差百分数。"""
    fig, ax = new_fig(left=0.19)
    n = ["N1", "N2", "N3", "N4", "N5", "N6", "N7"]
    d = [2.1, -1.4, 3.6, -4.2, 0.8, 5.1, -2.7]
    cols = [C1 if v >= 0 else C3 for v in d]
    bars = ax.barh(range(len(n)), d, height=0.56, color=cols, edgecolor="0.35",
                   linewidth=0.5)
    ax.axvline(0, color=C4, lw=0.6)
    ax.axvline(7, color=C2, lw=0.6, ls="--", label="上限 +7%")
    ax.axvline(-7, color=C2, lw=0.6, ls="--", label="下限 -7%")
    for b, v in zip(bars, d):
        ax.text(v + (0.35 if v >= 0 else -0.35), b.get_y() + b.get_height() / 2,
                f"{v:+.1f}", va="center",
                ha="left" if v >= 0 else "right", fontsize=FS - 2)
    ax.set_yticks(range(len(n)))
    ax.set_yticklabels(n)
    ax.set_ylabel("节点")
    ax.set_xlabel("电压偏差 / %")
    ax.set_xlim(-9, 9)
    legend(ax, "lower right", ncol=1)
    save(fig, "04_条形", "04_条形_各节点电压偏差")

def barh_04():
    """主要电气设备额定容量。"""
    fig, ax = new_fig(left=0.30)
    d = ["主变 T1", "主变 T2", "储能 PCS", "SVG", "光伏逆变器", "柴油机"]
    c = [50, 40, 10, 6, 5, 2]
    bars = ax.barh(range(len(d)), c, height=0.58, color=C1, edgecolor="0.35",
                   linewidth=0.5)
    for b, v in zip(bars, c):
        ax.text(v + 0.9, b.get_y() + b.get_height() / 2, f"{v}", va="center",
                fontsize=FS - 2)
    ax.set_yticks(range(len(d)))
    ax.set_yticklabels(d)
    ax.set_ylabel("设备")
    ax.set_xlabel("额定容量 " + IT["S"] + " / (MV·A)")
    ax.set_xlim(0, 58)
    save(fig, "04_条形", "04_条形_主要设备额定容量")

def barh_05():
    """四种储能配置方案的年化费用构成对比(堆叠条形)。"""
    fig, ax = new_fig(left=0.21)
    plan = ["方案 A", "方案 B", "方案 C", "方案 D"]
    inv = np.array([420, 365, 318, 402])
    ope = np.array([88, 96, 112, 82])
    pen = np.array([46, 32, 21, 58])
    ax.barh(range(len(plan)), inv, height=0.55, color=C1, edgecolor="0.35",
            linewidth=0.5, label="投资摊销")
    ax.barh(range(len(plan)), ope, left=inv, height=0.55, color=C3,
            edgecolor="0.35", linewidth=0.5, label="运行维护")
    ax.barh(range(len(plan)), pen, left=inv + ope, height=0.55, color=C5,
            edgecolor="0.35", linewidth=0.5, label="惩罚费用")
    for i, tot in enumerate(inv + ope + pen):
        ax.text(tot + 12, i, f"{tot:.0f}", va="center", fontsize=FS - 2)
    ax.set_yticks(range(len(plan)))
    ax.set_yticklabels(plan)
    ax.set_ylabel("配置方案")
    ax.set_xlabel("年化费用 / 万元")
    ax.set_xlim(0, 1080)
    legend(ax, "lower right", ncol=1)
    save(fig, "04_条形", "04_条形_储能方案费用构成")

说明

  • 图片 1181×944 px(100 mm × 80 mm @ 300 dpi),三维图为 1181×1122 px。
  • 图内不放标题,图题由本文件的标题承担。
  • 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定,重跑结果一致。
posted on 2026-11-07 01:02  小青蛙电气  阅读(3)  评论(0)    收藏  举报