17 类别分面图 catplot
17 类别分面图 catplot
这类图是什么
figure 级类别图,八种 kind 任选并分面。
看什么:按区域/方案等变量切子图,横向比较类别分布。
5 个案例
17-1 按区域分面的箱线图:一场对比两种区域的电压分布

17-2 按方案分面的线损率小提琴

17-3 按馈线分面的负荷率柱状

17-4 按天气分面的光伏出力散点(条带)

17-5 按季度分面的温升点线图

代码
5 个函数取自 code/第三批_类别图261107.py。关键约束:不调用 sns.set_theme(),否则 font.family 被改成 Arial,中文会变方框;版式由 code/公共配置261107.py 里的 setup_cn_style() 与 save() / save_grid() 统一接管。
# 摘自 code/第三批_类别图261107.py
def ct_01():
"""按区域分面的箱线图:一场对比两种区域的电压分布。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(1701)
rows = []
for area, mu, sd in [("城区", 10.15, 0.09), ("农村", 9.93, 0.18)]:
for seg, off in [("峰段", 0.06), ("谷段", -0.04)]:
d = rng.normal(mu + off, sd, 120)
rows.append(pd.DataFrame({"电压": d, "时段": seg, "区域": area}))
df = pd.concat(rows, ignore_index=True)
g = sns.catplot(data=df, x="时段", y="电压", col="区域", kind="box",
palette=[C5, C1], height=3.15, aspect=0.78, width=0.5,
linewidth=0.6, fliersize=2.0)
g.set_axis_labels("时段", "母线电压 " + IT["U"] + " / kV")
save_grid(g, "17_类别分面图", "17_类别分面图_按区域分面电压",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def ct_02():
"""按方案分面的线损率小提琴。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(1702)
rows = []
for plan, mu, sd in [("原状", 4.62, 0.28), ("方案一", 3.71, 0.24)]:
for seg, off in [("峰段", 0.3), ("谷段", -0.2)]:
d = rng.normal(mu + off, sd, 160)
rows.append(pd.DataFrame({"线损率": d, "时段": seg, "方案": plan}))
df = pd.concat(rows, ignore_index=True)
g = sns.catplot(data=df, x="时段", y="线损率", col="方案", kind="violin",
palette=[C5, C1], height=3.15, aspect=0.78, linewidth=0.5,
inner="box")
g.set_axis_labels("时段", "年线损率 / %")
save_grid(g, "17_类别分面图", "17_类别分面图_按方案分面线损",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def ct_03():
"""按馈线分面的负荷率柱状。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(1703)
rows = []
for fd, base in [("L1", 0.78), ("L2", 0.66)]:
for seg, off in [("峰段", 0.10), ("平段", 0.0), ("谷段", -0.12)]:
d = rng.normal(base + off, 0.04, 100)
rows.append(pd.DataFrame({"负荷率": d, "时段": seg, "馈线": fd}))
df = pd.concat(rows, ignore_index=True)
g = sns.catplot(data=df, x="时段", y="负荷率", col="馈线", kind="bar",
palette=[C5, C1], height=3.15, aspect=0.78, width=0.55,
linewidth=0.5, errorbar=("ci", 95), capsize=0.08)
g.set_axis_labels("时段", "日负荷率")
save_grid(g, "17_类别分面图", "17_类别分面图_按馈线分面负荷率",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def ct_04():
"""按天气分面的光伏出力散点(条带)。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(1704)
rows = []
for w, mu in [("晴天", 620), ("多云", 380)]:
for seg, off in [("上午", -80), ("中午", 60), ("下午", -40)]:
d = rng.normal(mu + off, 70, 40)
rows.append(pd.DataFrame({"出力": d, "时段": seg, "天气": w}))
df = pd.concat(rows, ignore_index=True)
g = sns.catplot(data=df, x="时段", y="出力", col="天气", kind="strip",
palette=[C3, C5], height=3.15, aspect=0.78, jitter=0.18,
size=3.0, edgecolor="white", linewidth=0.3)
g.set_axis_labels("时段", "有功出力 " + IT["P"] + " / kW")
save_grid(g, "17_类别分面图", "17_类别分面图_按天气分面光伏",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def ct_05():
"""按季度分面的温升点线图。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(1705)
rows = []
for q, off in [("上半月", 0.0), ("下半月", 3.0)]:
for L in [0.6, 0.8, 1.0, 1.2]:
d = rng.normal(28 + 26 * L ** 2 + off, 2.6, 70)
rows.append(pd.DataFrame({"温升": d, "负载率": f"{L:.1f}", "月份": q}))
df = pd.concat(rows, ignore_index=True)
g = sns.catplot(data=df, x="负载率", y="温升", col="月份", kind="point",
color=C1, height=3.15, aspect=0.82, markers="o", ms=4,
lw=1.0, capsize=0.10, errorbar=("ci", 95))
g.set_axis_labels("负载率 " + IT["beta"], "顶层油温升 " + IT["T"] + " / K")
save_grid(g, "17_类别分面图", "17_类别分面图_按月份分面温升",
left=0.14, bottom=0.21, right=0.97, top=0.84)
说明
- axes 级图 1181×944 px;figure 级多轴图按内容取 1100~1470 px 宽。
- 图内不放标题,图题由本文件的标题承担。
- 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定。

浙公网安备 33010602011771号