首页 > 解决方案 > 使用 seaborn 循环轴以创建散点图

问题描述

我正在尝试使用目标变量和 9 个连续变量创建 9 个散点图。

我想不出一种方法来遍历每个轴以绘制每个连续变量对目标的散点图。

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

fig, ax = plt.subplots(nrows=5, ncols=3, figsize=(16, 8))
sns.scatterplot(x=df['cont0'], y=df['target'], ax=ax[0, 0])
sns.scatterplot(x=df['cont1'], y=df['target'], ax=ax[0, 1])
sns.scatterplot(x=df['cont2'], y=df['target'], ax=ax[0, 2])
sns.scatterplot(x=df['cont3'], y=df['target'], ax=ax[1, 0])
sns.scatterplot(x=df['cont4'], y=df['target'], ax=ax[1, 1])
sns.scatterplot(x=df['cont5'], y=df['target'], ax=ax[1, 2])
sns.scatterplot(x=df['cont6'], y=df['target'], ax=ax[2, 0])
sns.scatterplot(x=df['cont7'], y=df['target'], ax=ax[2, 1])
sns.scatterplot(x=df['cont8'], y=df['target'], ax=ax[2, 2])

我怎样才能更有效地做到这一点?

标签: pythonpandasmatplotlibseaborn

解决方案


推荐阅读