Count plots

Seaborn basics

1 min read

Published Oct 7 2025


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 sns
import 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 sns
import 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 sns
import 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 sns
import 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 sns
import 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 sns
import 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

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact