1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| def show_num_hist(df, targets, col=None, row=None): for target in targets: g = sns.FacetGrid(df, col=col, row=row) g.map(plt.hist,target, bins=20) plt.show()
def show_num_barplot(df, col=None, row=None, x=None, y=None, hue=None,ci=None): grid = sns.FacetGrid(df,col=col,row=row) grid.map(sns.barplot,x,y,hue=hue,ci=ci) grid.add_legend() plt.show()
def show_num_violinplot(df, col=None, row=None, x=None, y=None, hue=None,ci=None): grid = sns.FacetGrid(df,col=col,row=row) grid.map(sns.violinplot,x,y,hue=hue) grid.add_legend() plt.show()
def num_to_label(df,num_column,bins=5): length = int(np.sqrt(len(num_column))) + 1 fig = plt.figure() grid = gridspec.GridSpec(length,length,fig) for a_len in range(length): for a_width in range(length): ax = fig.add_subplot(grid[a_width,a_len]) index = a_len * length + a_width if index < len(num_column): new_column_name = num_column[index] + 'Band' df[new_column_name] = pd.qcut(df[num_column[index]],bins) sns.pointplot(data=df,ax=ax, x=new_column_name, y='Survived') plt.setp( ax.get_xticklabels(), rotation=30, horizontalalignment='right', fontsize='x-small' ) plt.tight_layout() plt.show()
|