Count plots

Seaborn basics

1 min read

Published Oct 7 2025, updated Aug 17 2026


24
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation

seaborn.countplot() is used to count the number of occurrences of each category in a variable and display those counts as bars.

It’s basically like a barplot of counts, except you don’t need to compute the counts yourself — Seaborn does it automatically.


Syntax:

sns.countplot(    data=None,    x=None,    y=None,    hue=None,    order=None,    hue_order=None,    palette=None,    orient=None,    dodge=True,    width=0.8,    **kwargs)

Parameters:

  • data = DataFrame containing the data
  • x, y = Variable(s) for categories (only one is usually needed)
  • hue = Adds subcategories (grouped bars)
  • order / hue_order = Order of categories/subcategories
  • palette = Colour palette
  • orient = "v" (vertical) or "h" (horizontal)
  • dodge = Separate hue bars side by side (default: True)
  • width = Bar width




Basic example

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.countplot(data=tips, x="day")plt.show()

This shows how many records (meals) occurred on each day of the week.


seaborn count plot basic example





Add hue (subgroups)

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.countplot(data=tips, x="day", hue="sex")plt.show()

  • Bars are split by sex.
  • Each day shows two bars — one for each group in sex.

seaborn count plot hue example





Horizontal bars

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.countplot(data=tips, y="day", hue="sex", orient="h")plt.show()

Flips the bars horizontally — helpful for long category names.


seaborn count plot horizontal example





Specify category order

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.countplot(    data=tips,    x="day",    order=["Sun", "Sat", "Fri", "Thur"])plt.show()

Controls the order of bars along the x-axis.


seaborn count plot order example





Customise colours and style

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.countplot(    data=tips,    x="day",    hue="sex",    palette="coolwarm",    edgecolor="black",    width=0.7)plt.show()

  • palette="coolwarm" → colourful scheme
  • edgecolor="black" → outlines bars
  • width=0.7 → slightly thinner bars

seaborn count plot colour style example





Count of multiple variables (via hue)

import seaborn as snsimport matplotlib.pyplot as plt​tips = sns.load_dataset("tips")​sns.countplot(data=tips, x="smoker", hue="sex")plt.show()

Shows how many male vs. female smokers and non-smokers there are.


seaborn count plot multiple variables example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact