Skip to content

Instantly share code, notes, and snippets.

@netsatsawat
Created May 19, 2019 09:36
Show Gist options
  • Save netsatsawat/c968e46c37602d6be1004f26e4e7c5e8 to your computer and use it in GitHub Desktop.
Save netsatsawat/c968e46c37602d6be1004f26e4e7c5e8 to your computer and use it in GitHub Desktop.
Visualization for question 3 in HR analytics blog
_tmp_order = ['Bad', 'Good', 'Better', 'Best']
f, axes = plt.subplots(2, 2, figsize=(14, 14))
sns.countplot(x='WorkLifeBalance', hue='Attrition', palette={'Yes': 'r', 'No': 'skyblue'},
data=data_df, order=_tmp_order, ax=axes[0][0])
axes[0][0].set_title('Overall Work Life Balance')
sns.boxplot(x='WorkLifeBalance', y='DistanceFromHome', hue='Attrition',
palette={'Yes': 'r', 'No': 'skyblue'},
data=data_df, order=_tmp_order, ax=axes[0][1])
axes[0][1].set_title('Compare with distance from home')
sns.countplot(x='WorkLifeBalance', hue='Attrition', palette={'Yes': 'r', 'No': 'skyblue'},
data=data_df[data_df.OverTime == 'Yes'],
order=_tmp_order, ax=axes[1][0])
axes[1][0].set_title('Work life balance of Overtime employees')
sns.countplot(x='WorkLifeBalance', hue='Attrition', palette={'Yes': 'r', 'No': 'skyblue'},
data=data_df[data_df.OverTime != 'Yes'],
order=_tmp_order, ax=axes[1][1])
axes[1][1].set_title('Work life balance of Non-overtime employees')
handles, labels = axes[0][0].get_legend_handles_labels()
axes[0, 0].legend(handles[:0], labels[:0])
axes[0, 1].legend(handles[:0], labels[:0])
axes[1, 0].legend(handles[:0], labels[:0])
axes[1, 1].legend(handles[:0], labels[:0])
l = plt.legend(handles[0:2], labels[0:2], bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment