countplot with normalized y axis per group

With newer versions of seaborn you can do following: import numpy as np import pandas as pd import seaborn as sns sns.set(color_codes=True) df = sns.load_dataset(‘titanic’) df.head() x,y = ‘class’, ‘survived’ (df .groupby(x)[y] .value_counts(normalize=True) .mul(100) .rename(‘percent’) .reset_index() .pipe((sns.catplot,’data’), x=x,y=’percent’,hue=y,kind=’bar’)) output Update: Also show percentages on top of barplots If you also want percentages, you can do … Read more

How do I plot two countplot graphs side by side? [duplicate]

Something like this: import seaborn as sns import pandas as pd import matplotlib.pyplot as plt batData = [‘a’,’b’,’c’,’a’,’c’] bowlData = [‘b’,’a’,’d’,’d’,’a’] df=pd.DataFrame() df[‘batting’]=batData df[‘bowling’]=bowlData fig, ax =plt.subplots(1,2) sns.countplot(df[‘batting’], ax=ax[0]) sns.countplot(df[‘bowling’], ax=ax[1]) fig.show() The idea is to specify the subplots in the figure – there are numerous ways to do this but the above will work … Read more

plotting value_counts() in seaborn barplot

In the latest seaborn, you can use the countplot function: seaborn.countplot(x=’reputation’, data=df) To do it with barplot you’d need something like this: seaborn.barplot(x=df.reputation.value_counts().index, y=df.reputation.value_counts()) You can’t pass ‘reputation’ as a column name to x while also passing the counts in y. Passing ‘reputation’ for x will use the values of df.reputation (all of them, not … Read more

File not found.