Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 38 ยท Relational and Categorical Plots

Strip and Swarm Plots

Use seaborn stripplot and swarmplot to show every observation per category. Control jitter, dodge, hue, size and overlay points on box or violin plots.

Summaries are convenient, but they discard the individual data points. stripplot and swarmplot keep them. Both draw one dot per row along a category axis; they differ in how they separate dots that would otherwise land on top of each other. For small and medium datasets, they are often the most honest chart you can make.

stripplot: jittered dots

stripplot places dots at the category position and adds random horizontal jitter so overlapping values spread out a little. It is fast and works with any amount of data.

Python stripplot with jitter and hue

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.

Options:

  • jitter=True (default, a small amount), a number such as 0.2 (width in category units), or False.
  • dodge=True splits hue groups side by side instead of drawing them in the same column.
  • size=4 sets marker size in points (use size, not s, for these functions); alpha adds transparency; edgecolor="gray" with linewidth=0.5 outlines dots.
  • orient="h" or swapped x and y for horizontal.
  • native_scale=True keeps numeric categories at their true positions rather than evenly spaced.

Jitter is noise on the category axis only; it never changes the y values. Because it is random, the exact layout changes between runs; seed NumPy's generator or pass a fixed random state if you need reproducible pictures.

swarmplot: no overlaps

swarmplot positions points using an algorithm that moves them sideways just enough so none overlap, producing the "beeswarm" shape: wide where many values are similar, narrow where few are. The outline reveals the distribution while every point stays visible.

Python swarmplot and the density shape

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.

The treatment group has two clusters (a bimodal shape). The box plot summarizes it as one box with a plausible median; the swarm shows the gap. This is the main reason to look at raw points.

Swarm plot cautions:

  • It is slower than strip plot, and with thousands of points the swarm grows so wide that points cannot all be placed. Seaborn warns: "X% of the points cannot be placed". Use a strip plot, smaller size, or a violin or box plot instead.
  • Marker size changes the layout, because the algorithm avoids overlap based on size.
  • Dots near the same y but different groups of data may be moved by the swarm algorithm. The y value is still exact.

Points over summaries

A powerful pattern is to draw a distribution summary and the raw points together. Draw the summary first, then the points over it, and keep the points small and dark enough:

Python Box plot with swarm on top

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.

showfliers=False removes the box plot's own outlier dots, since the swarm already shows every point. This combination keeps the summary quartiles and the full data.

strip or swarm?

stripplot swarmplot
Overlap Random jitter, can overlap Avoided
Speed Fast, any size Slow for thousands of rows
Reproducible layout Random Deterministic
Good for Big or quick plots, alpha Up to about a few hundred points per category

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is jitter in a stripplot?

    Jitter moves points along the category axis only. The numeric values stay exact.
  2. 2. Why use a swarmplot instead of a boxplot for two small groups?

    Boxes summarize; swarms show the actual observations.
  3. 3. A swarmplot warns that some points cannot be placed. What should you do?

    Too many points per category cannot all be arranged without overlap. Use a smaller marker or another plot.
  4. 4. Why set showfliers=False when overlaying a swarm on a box plot?

    Otherwise outliers appear twice, once as box fliers and once as swarm dots.

Summary

  • stripplot draws every point with random jitter; swarmplot arranges points so none overlap.
  • Use jitter, dodge, size, alpha and hue to tune them; size (not s) sets marker size.
  • Raw points reveal clusters and outliers that summaries hide.
  • Swarm plots are slow and can fail with large data.
  • Overlay points on box or violin plots, with showfliers=False, to show both summary and data.

Next: Box, Boxen and Violin Plots