text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

hr_attrition = pd.read_csv('../input/WA_Fn-UseC_-HR-Employee-Attrition.csv', header=0)
hr_attrition.columns.values

###########################################################################################
# Define a common module for drawing subplots
# This module will draw subplot based on the parameters 
# There will be mutiple subplots within the main plotting window
#  Defination of the parameters are-
#  var_Name - this is the variable name from the data file
#  tittle_Name - this is the Tittle name give for the plot
#  nrow & ncol - this is the number of subplots within the main plotting window
#  idx - position of subplot in the main plotting window
#  fz - the font size of Tittle in the main plotting window
##########################################################################################
def draw_subplots(var_Name,tittle_Name,nrow=1,ncol=1,idx=1,fz=10):
    ax = plt.subplot(nrow,ncol,idx)
    ax.set_title('Distribution of '+var_Name)
    plt.suptitle(tittle_Name, fontsize=fz)

numeric_columns = ['Age', 'MonthlyIncome', 'TotalWorkingYears']

fig,ax = plt.subplots(1,1, figsize=(10,10))
j=0  # reset the counter to plot 
title_Str="Plotting the density distribution of various numeric Features"

for i in numeric_columns:
    j +=1
    draw_subplots(i,title_Str,3,1,j,20) # create a 1x3 subplots for plotting distribution plots
    sns.distplot(hr_attrition[i])
    plt.xlabel('')

numeric_columns = ['Age', 'DistanceFromHome', 'TotalWorkingYears', 'YearsAtCompany', 'Education', 'StockOptionLevel']
fig, ax = plt.subplots(1, 1, figsize=(15, 15))
j = 0
title_Str = 'Plotting the count distributions of various numeric Features'
for i in numeric_columns:
    j += 1
    draw_subplots(i, title_Str, 3, 2, j, 20)
    sns.countplot(hr_attrition[i], hue=hr_attrition['Attrition'])
    plt.xlabel('')