03 关系分面图 relplot
这类图是什么
figure 级关系图,用 col/row 按变量切子图并共享坐标轴。
看什么:比较多组之间的关系差异,不必手写 subplots 循环。
5 个案例
03-1 按季节分面的负荷—温度关系
relplot 的 col 参数按变量切子图并共享坐标轴,各组之间的关系差异直接并排可见,不必手工循环 subplots。

03-2 按供电区域分面的电压—电流关系

03-3 按天气分面的光伏出力曲线

03-4 按馈线分面的日负荷曲线

03-5 按年份分面的负荷增长散点

代码
5 个函数取自 code/第一批_关系图261107.py。关键约束:不调用 sns.set_theme(),否则 font.family 被改成 Arial,中文会变方框;版式由 code/公共配置261107.py 里的 setup_cn_style() 与 save() / save_grid() 统一接管。
# 摘自 code/第一批_关系图261107.py
def rl_01():
"""按季节分面的负荷—温度关系。
relplot 的 col 参数按变量切子图并共享坐标轴,各组之间的关系差异直接并排可见,
不必手工循环 subplots。
"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(301)
rows = []
for season, tmu, slope in [("春季", 18, 6.2), ("夏季", 30, 11.5)]:
for _ in range(160):
t = rng.normal(tmu, 5.5)
p = 380 + slope * (t - 10) + rng.normal(0, 45)
rows.append((season, t, p))
df = pd.DataFrame(rows, columns=["季节", "气温", "负荷"])
g = sns.relplot(data=df, x="气温", y="负荷", hue="季节", col="季节",
palette=PALETTE3[:2], height=3.15, aspect=0.78,
s=18, edgecolor="white", linewidth=0.3, legend=False)
g.set_axis_labels("气温 " + IT["T"] + " / °C", "有功负荷 " + IT["P"] + " / kW")
save_grid(g, "03_关系分面图", "03_关系分面图_按季节分面负荷温度",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def rl_02():
"""按供电区域分面的电压—电流关系。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(302)
rows = []
for area, u0, k in [("城区", 10.20, 0.00085), ("农村", 10.05, 0.0014)]:
for _ in range(150):
i = rng.gamma(9, 30)
u = u0 - k * i + rng.normal(0, 0.04)
rows.append((area, i, u))
df = pd.DataFrame(rows, columns=["区域", "电流", "电压"])
g = sns.relplot(data=df, x="电流", y="电压", col="区域", hue="区域",
palette=PALETTE3[:2], height=3.15, aspect=0.78, s=16,
edgecolor="white", linewidth=0.3, legend=False)
g.set_axis_labels("负荷电流 " + IT["I"] + " / A", "母线电压 " + IT["U"] + " / kV")
save_grid(g, "03_关系分面图", "03_关系分面图_按区域分面电压电流",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def rl_03():
"""按天气分面的光伏出力曲线。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(303)
rows = []
for weather, k in [("晴天", 1.0), ("多云", 0.6)]:
for d in range(10):
for h in np.arange(6, 19, 1.0):
p = k * 860 * np.sin((h - 6) / 13 * np.pi) ** 1.3 * (1 + rng.normal(0, 0.08))
rows.append((weather, h, max(p, 0)))
df = pd.DataFrame(rows, columns=["天气", "时刻", "出力"])
g = sns.relplot(data=df, x="时刻", y="出力", col="天气", hue="天气",
kind="line", palette=PALETTE3[:2], height=3.15, aspect=0.78,
lw=1.0, legend=False, errorbar=("ci", 95))
g.set_axis_labels("时刻 " + IT["t"] + " / h", "有功出力 " + IT["P"] + " / kW")
save_grid(g, "03_关系分面图", "03_关系分面图_按天气分面光伏出力",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def rl_04():
"""按馈线分面的日负荷曲线。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(304)
rows = []
for fd, base in [("L1", 480), ("L2", 320)]:
for d in range(15):
for h in np.arange(0, 24, 1.0):
p = base + 0.35 * base * np.exp(-((h - 10) / 3.4) ** 2) \
+ 0.45 * base * np.exp(-((h - 17) / 3.0) ** 2) + rng.normal(0, 22)
rows.append((fd, h, p))
df = pd.DataFrame(rows, columns=["馈线", "时刻", "负荷"])
g = sns.relplot(data=df, x="时刻", y="负荷", col="馈线", hue="馈线",
kind="line", palette=PALETTE3[:2], height=3.15, aspect=0.78,
lw=1.0, legend=False)
g.set_axis_labels("时刻 " + IT["t"] + " / h", "有功负荷 " + IT["P"] + " / kW")
save_grid(g, "03_关系分面图", "03_关系分面图_按馈线分面日负荷",
left=0.14, bottom=0.21, right=0.97, top=0.84)
def rl_05():
"""按年份分面的负荷增长散点。"""
fig, ax = new_fig(left=0.19)
fig.delaxes(ax)
rng = np.random.default_rng(305)
rows = []
for year, scale in [("2023 年", 1.0), ("2025 年", 1.16)]:
for _ in range(140):
t = rng.normal(26, 7)
p = scale * (400 + 9.6 * (t - 12)) + rng.normal(0, 48)
rows.append((year, t, p))
df = pd.DataFrame(rows, columns=["年份", "气温", "负荷"])
g = sns.relplot(data=df, x="气温", y="负荷", col="年份", hue="年份",
palette=PALETTE3[:2], height=3.15, aspect=0.78, s=16,
edgecolor="white", linewidth=0.3, legend=False)
g.set_axis_labels("气温 " + IT["T"] + " / °C", "有功负荷 " + IT["P"] + " / kW")
save_grid(g, "03_关系分面图", "03_关系分面图_按年份分面负荷增长",
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号