使用循环的SNS子图

时间:2019-03-22 06:53:01

标签: python-3.x python-2.7 seaborn

我想遍历列表g以使用

进行子绘图
ax = sns.countplot(x='salary', hue="left", data=df)

g = ['salary', 'Gender ','Marrital Status', 'EducationLevel', 'Overtime', 
     'Stock Level', 'Experience ', 'Role', 'Business Travel']

g是数据框中的类别列表,显示员工流失。我将属性left作为标签,并想针对标签

绘制列表g中的类别

我的尝试:

g = ['salary', 'Gender ', 'Marrital Status', 'EducationLevel', 'Overtime', 'Stock Level', 'Experience ', 'Role', 'Business Travel'] 
for i in g: 
    ax = sns.countplot(x=i, hue="left", data=df)

1 个答案:

答案 0 :(得分:0)

尝试

g = ['salary', 'Gender ', 'Marrital Status', 'EducationLevel', 'Overtime', 'Stock Level', 'Experience ', 'Role', 'Business Travel'] 
ax = [sns.countplot(x=i, hue="left", data=df) for i in g]