简体   繁体   English

绘制 seaborn 箱线图

[英]Draw seaborn boxplots

I work in an updated version of anaconda and the following code is not working correctly nowadays:我在 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);

Something like this should be drawn:应该画出这样的东西:

在此处输入图像描述

I don't understand how to fix my above code, now it only draws boxes, but the graphics inside them are not我不明白如何修复上面的代码,现在它只绘制框,但它们里面的图形不是

在此处输入图像描述

I downloaded the data from this link and seems like the column is "churn" instead of "Churn".我从此链接下载了数据,似乎该列是“流失”而不是“流失”。 You might have renamed the column, so please provide the dataset somehow.您可能已重命名该列,因此请以某种方式提供数据集。

Using the file downloaded, I selected 12 numeric features:使用下载的文件,我选择了 12 个数字特征:

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

And plot it by flattening the axes:和 plot 通过展平轴:

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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM