Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 42 ยท Statistical and Scientific Charts

Box, Violin and Strip Plots

Compare distributions with Plotly box, violin and strip plots: quartiles, whiskers, outliers, notches, means, split violins, jittered points and how to read each plot.

A histogram shows one distribution well, but it gets crowded when you want to compare five groups. Box plots, violin plots and strip plots put several distributions side by side along a category axis, using very little space. They are the standard tools for questions like "does the tip differ by day?" or "do the three species have different petal lengths?"

All three take the same arguments in Express: a categorical column for x (or y for horizontal plots) and a numeric column for the other axis.

Box plots

A box plot summarizes a distribution with five numbers:

  • The box spans the first quartile (Q1, 25% of data below) to the third quartile (Q3, 75% below). Its length is the interquartile range (IQR).
  • The line inside the box is the median (50%).
  • The whiskers reach the most extreme values within 1.5 x IQR from the box.
  • Points beyond the whiskers are drawn individually as outliers.
Python px.box and the numbers behind it

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 computed fence is where the upper whisker must stop; any bill above it is drawn as a dot. Plotly's default quartile method (linear) is close to pandas', but you can pick exclusive or inclusive with quartilemethod, and small differences are normal.

Useful options:

Option Effect
points "outliers" (default), "all", "suspectedoutliers", or False
notched=True Notches around the median show an approximate confidence interval. Non-overlapping notches suggest different medians.
boxmean=True / "sd" Draws a dashed line at the mean (and optionally the standard deviation)
boxmode group (side by side, default) or overlay
orientation="h" Horizontal boxes (swap x and y)
jitter, pointpos Spread and position of the points beside the box
whiskerwidth Width of the whisker caps

Violin plots

A violin plot replaces the box with a smoothed density shape: the wider the violin at a value, the more observations there are near that value. It shows what a box hides, such as two peaks (bimodality). Adding box=True draws a small box inside the violin, and points="all" shows the raw data.

Box, violin and strip plots in plotly.js

Both groups have almost the same center, but violin B has two bulges. A box plot of B would look like a perfectly ordinary box. This is the main reason to prefer violins when the shape of the distribution matters.

Violin options you will use:

  • box=True, points="all" or "outliers": what to draw inside.
  • violinmode="overlay" and side="positive" / "negative": draw half violins on each side of the axis to compare two groups in one violin (a split violin): set side per trace and violinmode="overlay".
  • meanline_visible=True: line at the mean.
  • bandwidth: smoothing of the density (larger = smoother).
  • spanmode="hard": cut the violin at the data's min and max instead of extending the tails.
  • scalemode="count": violin widths proportional to group size.

Strip plots

A strip plot is a scatter plot with one categorical axis: every observation is a dot, spread (jittered) sideways so dots do not hide each other. It shows each value, so you see sample size and clusters directly. It works well for small and medium datasets, and combines well with a box:

Python Violin, split violin and strip in Express

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.

Express implements a strip plot as a box trace with the box hidden and every point shown. That is why strip.data[0].type is box. It also means jitter and point position options match the box plot's.

Choosing between them

Plot Best when Watch out
Box Many groups, you care about median and spread, outliers matter Hides multimodality; can look identical for different shapes
Violin You want the shape, bimodality, skew Density smoothing can invent tails; small samples are misleading
Strip Small data, you want every value visible Overplotting for hundreds of points per group
Box + points Best compromise for moderate data Use points="all" with small jitter

Always show the sample size somewhere (hover text, group labels), because a box over five points is not the same as a box over five thousand.

Common mistakes

  • Reading the box as "the range of the data". It covers the middle 50%; the whiskers and outliers cover the rest.
  • Drawing a violin for tiny groups: with 5 points the density shape is just noise.
  • Forgetting to set the same y range or scale when comparing separate charts.
  • Using a color for something that the x axis already encodes. If each box is already labeled by day, extra color per day adds nothing; use color for a second variable.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. In a Plotly box plot, what does the box itself span?

    The box covers the middle 50% of the data; the line inside is the median.
  2. 2. What does a violin plot show that a box plot hides?

    The width of the violin reflects density, so bimodal or skewed distributions are visible.
  3. 3. How is px.strip implemented?

    The strip plot is a box trace with boxpoints="all" and invisible boxes.
  4. 4. Which points value shows every observation next to a box or violin?

    all draws all points; outliers only the points beyond the whiskers.
  5. 5. What do non-overlapping notches on two boxes suggest?

    Notches approximate a confidence interval for the median. Non-overlap is a hint of a real difference, not a proof.

Summary

  • Box plots summarize groups with the median, quartiles, whiskers (1.5 x IQR) and outliers.
  • Violin plots add the density shape; strip plots show every point with jitter.
  • Use points, notched, boxmean, box=True, side and violinmode for the common variations.
  • Pick the plot by what matters: summary (box), shape (violin), individual values (strip), and always consider the group sizes.

Next: Distribution Plots and ECDFs