How to make a "countplot" in seaborn, plotly and matplotlib

I find myself often needing to make a 'countplot'...

How to make a countplot

I find myself often needing to make a 'countplot'. I.e. a histogram of the counts of values of a particular field. Here's how to do it using different libraries. Sometimes you want quick, sometimes pretty, sometimes interactive.

Assume you dataframe is stored in df. And the column you are interested in is result

Combine with retina jupyter matplotlib settings for prettier output.

In matplotlib

df.result.plot.hist(bins=50)

In seaborn.

import seaborn as sns
sns.countplot(x='result', data=df)

In plotly express

import plotly.express as px
px.histogram(df, x="result")

If the graphs don't show, and you're using jupyter lab. Try: jupyter labextension install jupyterlab-plotly@4.12.0


I prefer to use seaborn for prettiest quick output.