09 条带图 stripplot
这类图是什么
类别轴上的散点,jitter 控制横向抖动。
看什么:样本少时展示每个点的位置,比箱线更保留原始信息。
5 个案例
09-1 四季负荷率的条带散点:每个样本一个点

09-2 各馈线电流的条带图:叠加均值横线

09-3 两种控制策略的效果对比条带图

09-4 分时段电压偏差条带:看离散范围

09-5 各月光伏出力的条带图:按月份分组着色

代码
5 个函数取自 code/第三批_类别图261107.py。关键约束:不调用 sns.set_theme(),否则 font.family 被改成 Arial,中文会变方框;版式由 code/公共配置261107.py 里的 setup_cn_style() 与 save() / save_grid() 统一接管。
# 摘自 code/第三批_类别图261107.py
def st_01():
"""四季负荷率的条带散点:每个样本一个点。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(901)
rows = []
for s, mu in [("春季", 0.72), ("夏季", 0.83), ("秋季", 0.77), ("冬季", 0.75)]:
rows.append(pd.DataFrame({"负荷率": rng.normal(mu, 0.055, 40), "季节": s}))
df = pd.concat(rows, ignore_index=True)
sns.stripplot(data=df, x="季节", y="负荷率", hue="季节", palette=PALETTE5,
jitter=0.22, size=3.2, edgecolor="white", linewidth=0.3,
legend=False, ax=ax)
ax.set_xlabel("季节")
ax.set_ylabel("日负荷率")
ax.set_ylim(0.55, 1.00)
save(fig, "09_条带图", "09_条带图_四季负荷率")
def st_02():
"""各馈线电流的条带图:叠加均值横线。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(902)
rows = []
for fd, mu in [("L1", 290), ("L2", 360), ("L3", 410), ("L4", 250)]:
rows.append(pd.DataFrame({"电流": rng.gamma(9, mu / 9, 45), "馈线": fd}))
df = pd.concat(rows, ignore_index=True)
sns.stripplot(data=df, x="馈线", y="电流", hue="馈线", palette=PALETTE4,
jitter=0.2, size=3.0, edgecolor="white", linewidth=0.3,
legend=False, ax=ax)
sns.pointplot(data=df, x="馈线", y="电流", color=C4, errorbar=None,
markers="D", ms=4, lw=0, ax=ax, legend=False)
ax.set_xlabel("馈线")
ax.set_ylabel("电流有效值 " + IT["I"] + " / A")
ax.set_ylim(150, 560)
save(fig, "09_条带图", "09_条带图_各馈线电流")
def st_03():
"""两种控制策略的效果对比条带图。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(903)
rows = []
for p, mu, sd in [("策略 A", 0.842, 0.018), ("策略 B", 0.918, 0.012)]:
rows.append(pd.DataFrame({"效率": rng.normal(mu, sd, 38), "策略": p}))
df = pd.concat(rows, ignore_index=True)
sns.stripplot(data=df, x="策略", y="效率", hue="策略", palette=[C5, C1],
jitter=0.18, size=3.6, edgecolor="white", linewidth=0.3,
legend=False, ax=ax)
ax.set_xlabel("控制策略")
ax.set_ylabel("系统综合效率 " + IT["eta"])
ax.set_ylim(0.79, 0.96)
save(fig, "09_条带图", "09_条带图_两策略效果")
def st_04():
"""分时段电压偏差条带:看离散范围。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(904)
rows = []
for seg, mu, sd in [("0-4", 0.4, 1.6), ("8-12", 1.2, 2.4),
("16-20", 2.1, 3.0), ("20-24", 0.9, 2.0)]:
rows.append(pd.DataFrame({"偏差": rng.normal(mu, sd, 42), "时段": seg}))
df = pd.concat(rows, ignore_index=True)
sns.stripplot(data=df, x="时段", y="偏差", hue="时段", palette=PALETTE4,
jitter=0.2, size=3.2, edgecolor="white", linewidth=0.3,
legend=False, ax=ax)
ax.axhline(7, color=C2, lw=0.7, ls="--")
ax.axhline(-7, color=C2, lw=0.7, ls=":")
ax.set_xlabel("时段 / h")
ax.set_ylabel("电压偏差 / %")
ax.set_ylim(-9, 11)
save(fig, "09_条带图", "09_条带图_分时段电压偏差")
def st_05():
"""各月光伏出力的条带图:按月份分组着色。"""
fig, ax = new_fig(left=0.19)
rng = np.random.default_rng(905)
rows = []
for m, mu in [("1 月", 210), ("4 月", 396), ("7 月", 486), ("10 月", 320)]:
rows.append(pd.DataFrame({"出力": rng.normal(mu, mu * 0.16, 40), "月份": m}))
df = pd.concat(rows, ignore_index=True)
sns.stripplot(data=df, x="月份", y="出力", hue="月份", palette=PALETTE4,
jitter=0.2, size=3.2, edgecolor="white", linewidth=0.3,
legend=False, ax=ax)
ax.set_xlabel("月份")
ax.set_ylabel("日均出力 " + IT["P"] + " / kW")
ax.set_ylim(0, 760)
save(fig, "09_条带图", "09_条带图_各月光伏出力")
说明
- axes 级图 1181×944 px;figure 级多轴图按内容取 1100~1470 px 宽。
- 图内不放标题,图题由本文件的标题承担。
- 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定。
浙公网安备 33010602011771号