08 小提琴图 violinplot

用途

箱线加上密度形状,样本量大、存在多峰时比箱线更能说明问题。

示例(5 张)

08-1 各月光伏出力分布小提琴图

各月光伏出力分布小提琴图

08-2 各馈线电流分布小提琴图(含中位数)

各馈线电流分布小提琴图(含中位数)

08-3 四种储能调度策略的效率分布

四种储能调度策略的效率分布

08-4 四季风速分布小提琴图

四季风速分布小提琴图

08-5 三相电压不平衡度分布对比

三相电压不平衡度分布对比

代码

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

# 摘自 code/第二批_分布图型261106.py

def violin_01():
    """各月光伏出力分布小提琴图。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(301)
    means = [210, 268, 340, 396, 442, 470, 486, 468, 402, 320, 238, 196]
    data = [rng.normal(m, m * 0.16, 120).clip(0) for m in means]
    parts = ax.violinplot(data, showmedians=True, widths=0.75,
                          showextrema=False)
    for body in parts["bodies"]:
        body.set_facecolor(C5)
        body.set_edgecolor("0.35")
        body.set_linewidth(0.5)
        body.set_alpha(0.9)
    parts["cmedians"].set_color(C2)
    parts["cmedians"].set_linewidth(1.2)
    ax.set_xticks(range(1, 13))
    ax.set_xticklabels([str(i) for i in range(1, 13)])
    ax.set_xlabel("月份")
    ax.set_ylabel("日均出力 " + IT["P"] + " / kW")
    ax.set_ylim(-40, 780)
    save(fig, "08_小提琴", "08_小提琴_各月光伏出力")

def violin_02():
    """各馈线电流分布小提琴图(含中位数)。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(302)
    data = [rng.gamma(9, 32, 200), rng.gamma(11, 24, 200),
            rng.gamma(8, 46, 200), rng.gamma(14, 18, 200),
            rng.gamma(10, 30, 200)]
    parts = ax.violinplot(data, showmedians=True, widths=0.75,
                          showextrema=False)
    for body, c in zip(parts["bodies"], [C5, C1, C5, C3, C5]):
        body.set_facecolor(c)
        body.set_edgecolor("0.35")
        body.set_linewidth(0.5)
        body.set_alpha(0.9)
    parts["cmedians"].set_color(C2)
    parts["cmedians"].set_linewidth(1.2)
    ax.set_xticks(range(1, 6))
    ax.set_xticklabels(["L1", "L2", "L3", "L4", "L5"])
    ax.set_xlabel("馈线")
    ax.set_ylabel("电流有效值 " + IT["I"] + " / A")
    ax.set_ylim(0, 560)
    save(fig, "08_小提琴", "08_小提琴_各馈线电流分布")

def violin_03():
    """四种储能调度策略的效率分布。"""
    fig, ax = new_fig(left=0.20)
    rng = np.random.default_rng(303)
    data = [rng.normal(0.86, 0.022, 160), rng.normal(0.89, 0.018, 160),
            rng.normal(0.91, 0.015, 160), rng.normal(0.92, 0.012, 160)]
    parts = ax.violinplot(data, showmedians=True, widths=0.72,
                          showextrema=False)
    for body, c in zip(parts["bodies"], [C6, C5, C1, C3]):
        body.set_facecolor(c)
        body.set_edgecolor("0.35")
        body.set_linewidth(0.5)
        body.set_alpha(0.9)
    parts["cmedians"].set_color(C2)
    parts["cmedians"].set_linewidth(1.2)
    ax.set_xticks([1, 2, 3, 4])
    ax.set_xticklabels(["策略一", "策略二", "策略三", "策略四"])
    ax.set_xlabel("调度策略")
    ax.set_ylabel("综合效率 " + IT["eta"])
    ax.set_ylim(0.80, 0.96)
    save(fig, "08_小提琴", "08_小提琴_储能策略效率分布")

def violin_04():
    """四季风速分布小提琴图。"""
    fig, ax = new_fig(left=0.19)
    rng = np.random.default_rng(304)
    shapes = [(2.4, 9.2), (1.9, 6.8), (2.2, 7.6), (2.7, 10.4)]
    data = [lam * rng.weibull(k, 240) for k, lam in shapes]
    parts = ax.violinplot(data, showmedians=True, widths=0.75,
                          showextrema=False)
    for body, c in zip(parts["bodies"], [C5, C1, C3, C5]):
        body.set_facecolor(c)
        body.set_edgecolor("0.35")
        body.set_linewidth(0.5)
        body.set_alpha(0.9)
    parts["cmedians"].set_color(C2)
    parts["cmedians"].set_linewidth(1.2)
    ax.set_xticks([1, 2, 3, 4])
    ax.set_xticklabels(["春季", "夏季", "秋季", "冬季"])
    ax.set_xlabel("季节")
    ax.set_ylabel("风速 " + IT["v"] + " / (m/s)")
    ax.set_ylim(0, 26)
    save(fig, "08_小提琴", "08_小提琴_四季风速分布")

def violin_05():
    """三相电压不平衡度分布对比。"""
    fig, ax = new_fig(left=0.20)
    rng = np.random.default_rng(305)
    data = [rng.gamma(5.5, 0.42, 220), rng.gamma(7.2, 0.36, 220),
            rng.gamma(4.4, 0.50, 220)]
    parts = ax.violinplot(data, showmedians=True, widths=0.7,
                          showextrema=False)
    for body, c in zip(parts["bodies"], [C5, C1, C3]):
        body.set_facecolor(c)
        body.set_edgecolor("0.35")
        body.set_linewidth(0.5)
        body.set_alpha(0.9)
    parts["cmedians"].set_color(C2)
    parts["cmedians"].set_linewidth(1.2)
    ax.axhline(2.0, color=C2, lw=0.8, ls="--", label="限值 2.0%")
    ax.set_xticks([1, 2, 3])
    ax.set_xticklabels(["节点 A", "节点 B", "节点 C"])
    ax.set_xlabel("监测节点")
    ax.set_ylabel("电压不平衡度 / %")
    ax.set_ylim(0, 12)
    legend(ax, "upper right", ncol=1)
    save(fig, "08_小提琴", "08_小提琴_三相电压不平衡度")

说明

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