Skip to content

Instantly share code, notes, and snippets.

@albertorb
Created June 17, 2019 09:39
Show Gist options
  • Save albertorb/db7dbf6bac160a2df5ce4bc1d4a643da to your computer and use it in GitHub Desktop.
Save albertorb/db7dbf6bac160a2df5ce4bc1d4a643da to your computer and use it in GitHub Desktop.
Plot all categoricals within the same cell with seaborn's countplot.
import numpy as np
import seaborn as sns
import pylab as plt
def plot_all_cat_distributions(dataframe, figsize = (20,40)):
""" Plot every single category frequency distribution in the same cell"""
max_shape = np.ceil(dataframe.shape[1] / 2)
fig = plt.figure(figsize=figsize)
for i, col in enumerate(dataframe.columns):
plt.subplot(max_shape, 2, i+1)
_ = sns.countplot(y = col, data = dataframe, order=dataframe[col].value_counts().index)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment