考察点: seaborn 的 axes-level 函数(如 scatterplot)如何指定绘图目标坐标轴。
分析: Seaborn 的 axes-level 函数默认会在当前活动的 matplotlib axes 上绘图,或者如果没有指定且当前没有 axes,则创建一个新的。在代码fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))
执行后,ax2 是当前激活的 axes。代码sns.scatterplot(data=df, x='height', y='weight')
没有指定 ax 参数,因此它默认画在了 ax2 上。要画在 ax1 上,必须显式传递 ax=ax1 参数。