绘制 seaborn 箱线图

Draw seaborn boxplots

我在 anaconda 的更新版本中工作,现在以下代码无法正常工作:

fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(12, 9))

for idx, feat in  enumerate(features):
    sns.boxplot(x='Churn', y=feat, data=df, ax=axes[idx / 3, idx % 3]) # Axes object to draw the plot onto
    axes[idx / 3, idx % 3].legend()
    axes[idx / 3, idx % 3].set_xlabel('Churn')
    axes[idx / 3, idx % 3].set_ylabel(feat);

应该画这样的东西:

我不明白如何修复我上面的代码,现在它只画框,但里面的图形不是

我从这个 link 下载了数据,该列似乎是“流失”而不是“流失”。您可能已重命名该列,因此请以某种方式提供数据集。

使用下载的文件,我选择了 12 个数字特征:

df = pd.read_csv("../datasets_2667_4430_bigml_59c28831336c6604c800002a.csv")
features = df.columns[df.dtypes != object][:12]

并通过展平坐标轴来绘制它:

fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(12, 9))
axes = axes.flatten()
for idx, feat in  enumerate(features):
    sns.boxplot(x='churn', y=feat, data=df, ax=axes[idx])
    axes[idx].set_xlabel('churn')
    axes[idx].set_ylabel(feat)
fig.tight_layout()