Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 38 ยท Relational and Categorical Plots

Categorical Plots: Choosing the Right One

Overview of seaborn categorical plots: strip, swarm, box, boxen, violin, bar, count and point. Learn catplot, the kind argument, and how to pick by question.

When one of your variables is a category (day of the week, species, plan, region), scatter and line plots are not the right tool. Seaborn has a family of categorical plots that put the category on one axis and a number on the other, and show how the numbers are distributed or summarized within each category. There are eight of them, and the choice is a matter of what you want the reader to see.

The family at a glance

Show every point

stripplot One dot per row, jittered.
swarmplot Dots arranged so none overlap.

Best for small data, or on top of a summary.

1 / 3

One entry point: catplot

Each of these is an axes-level function. The figure-level catplot wraps all of them with a kind argument, and adds col= and row= faceting:

Python
sns.catplot(data=df, x="day", y="bill", kind="box")      # same as boxplot
sns.catplot(data=df, x="day", y="bill", kind="violin", col="time")

kind can be "strip" (the default), "swarm", "box", "violin", "boxen", "point", "bar" or "count".

Same data, eight views

Python Eight categorical plots of the same data

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All panels use the same rows, but they answer different questions. The strip and swarm plots show every point; box, boxen and violin show the shape; bar and point reduce each day to a mean; count ignores the y values entirely and counts rows.

Choosing: a decision guide

Question Plot
How many observations are in each category? countplot
What is the average per category, with uncertainty? barplot or pointplot
How are values spread, and are there outliers? boxplot
Is the distribution bimodal or skewed? violinplot (or boxenplot)
Large data, many quantiles boxenplot
Small data, I want to see everything swarmplot or stripplot
Compare means across two grouping variables pointplot with hue
A summary plus raw data Box or violin with a strip or swarm on top

A rule of thumb: when in doubt, show more of the data. A bar chart of means can hide that one group has two clusters, which a violin or swarm plot would reveal.

Shared arguments

All categorical functions share a core:

  • x= and y=: one is the category, the other numeric. Swap them for a horizontal plot, or set orient="h".
  • hue=: a second category, splitting each position into colored sub-groups.
  • order= and hue_order=: the order of categories.
  • palette= and color=: colors; saturation= softens them.
  • dodge=True|False: whether hue groups sit side by side.
  • width=: how wide each box or bar is.
  • ax= (axes-level) or col=, row=, height=, aspect= (catplot).
Python catplot with hue and facets

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Using a line to connect categories without natural order; pointplot lines are meaningful only for ordered or repeated conditions.
  • Bars that do not start at zero (bar length encodes the value).
  • Hiding small sample sizes: add countplot, or show the points.
  • Forgetting that barplot shows a mean, not a count.
  • Too many categories on the x axis: swap axes so the labels read horizontally.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which plot is BEST for showing how many observations fall in each category?

    countplot counts rows per category; the others summarize a numeric variable.
  2. 2. What does the kind argument of catplot select?

    catplot dispatches to stripplot, swarmplot, boxplot, violinplot, boxenplot, pointplot, barplot or countplot.
  3. 3. Why might a bar chart of group means be misleading?

    A single mean per group can hide the shape of the data, so show distributions when you can.
  4. 4. How do you create a horizontal boxplot?

    Seaborn infers the orientation from which axis is numeric; orient='h' makes it explicit.

Summary

  • Categorical plots put a category on one axis and a number on the other.
  • Show points (stripplot, swarmplot), distributions (boxplot, boxenplot, violinplot) or summaries (barplot, pointplot, countplot).
  • catplot(kind=...) is the figure-level entry point with col and row faceting.
  • Shared arguments: hue, order, hue_order, palette, dodge, orient.
  • Prefer plots that show the data's shape; use bars for summaries and counts.

Next: Strip and Swarm Plots