image_output_1.png
import seaborn as sns
import matplotlib.pyplot as plt
def plot_dist(name, frame, color='green'):
    name0 = '{}_'.format(name)
    ticklabel_op = True
    if name0 not in frame.columns:
        name0 = name
        ticklabel_op = False
    data_count = len(frame[name0].unique())
    if data_count > 3:
        sns.distplot(frame[name0], rug=False, color=color)
        if data_count < 10:
            plt.xticks(frame[name0].unique())
    else:
        sns.countplot(frame[name0], color=color)
    name1 = ''.join([char.upper() if i == 0 else char for i, char in enumerate(list(name))])
    if ticklabel_op == True:
        cat = dict(enumerate(frame[name].cat.categories))
        ax = plt.gca()
        if len(cat) > 5:
            rotation = 45
            ha = 'right'
        else:
            rotation = 0
            ha = 'center'
        ax.xaxis.set_ticklabels([cat[i] for i in sorted(frame[name0].unique())], rotation=rotation, ha=ha)
fig, ((ax1, ax2, ax3), (ax4, ax5, ax6), (ax7, ax8, ax9)) = plt.subplots(nrows=3, ncols=3, figsize=(12, 10))
plt.subplots_adjust(hspace=0.3, wspace=0.3)
cols_to_plot = list(frame.columns)
cols_to_plot.remove('left')
for ax, name in zip(fig.axes, cols_to_plot):
    plt.subplot(ax)
    plot_dist(name, frame)
    sns.despine()