Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 38 ยท Relational and Categorical Plots

Box, Boxen and Violin Plots

Read and draw seaborn box plots, boxen (letter-value) plots and violin plots: quartiles, whiskers, outliers, split violins, hue, inner marks and bandwidth.

Three plots compare the distribution of a numeric variable across categories: the box plot (a five-number summary), the boxen plot (many quantiles, for large data) and the violin plot (a mirrored density curve). They answer "how do these groups differ in center, spread and shape?" much better than a bar of means.

Anatomy of a box plot

Reading a box plot

Median The line inside the box. Half the data is below.
The box From Q1 to Q3. It holds the middle 50%.
Whiskers Reach to the furthest point within 1.5 x IQR.
Outliers Dots beyond the whiskers.

IQR = Q3 minus Q1, the height of the box.

1 / 2

A taller box means a wider spread. A median closer to one end of the box signals skew. Whiskers extend to the most extreme data point inside 1.5 times the box height; points beyond are drawn individually and called "fliers" in Matplotlib terms. They are flagged, not necessarily errors.

Python boxplot with 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.

Useful arguments: width (box width), whis (whisker length multiplier, default 1.5; (5, 95) makes whiskers percentiles), showfliers=False (hide outliers), notch=True (notches that suggest median uncertainty), fill=False (outline only), gap (space between hue boxes), linewidth, color, palette, and showmeans=True with meanprops to add the mean.

Strengths: compact, many groups side by side, robust to outliers. Weaknesses: hides the shape; a bimodal group and a unimodal one can have identical boxes. See Strip and Swarm Plots for adding the points.

boxenplot: for larger data

A standard box plot shows only four quantile marks, which wastes information once you have thousands of points. A boxen plot (also called a letter-value plot) draws a series of nested boxes: the biggest holds the middle 50%, the next the middle 75%, then 87.5%, and so on, getting narrower toward the tails. The number of boxes grows with the sample size, so it shows tail shape better.

Python Box vs boxen for 5,000 values

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 standard box plot draws a pile of outlier dots for the long-tailed group and little else about the tail. The boxen plot shows how the tail thins out stage by stage. Useful arguments: k_depth ("tukey", "proportion", "trustworthy", "full" or an integer number of levels), outlier_prop, width_method, plus the usual hue, order and palette.

violinplot: shape and summary

A violin plot mirrors a KDE on each side of the category position, so the width at any height shows how dense the data is there. By default a small box plot sits inside it.

Python Violin options: inner, split and bandwidth

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.

Key options:

Argument Effect
inner What is drawn inside: "box" (default), "quart"/"quartile", "point", "stick" (one line per data point) or None
split=True With a two-level hue, draws half a violin per level: compact comparison
density_norm Scaling of widths: "area" (each violin has the same area), "count" (width by group size), "width" (all the same maximum width)
common_norm Use one scale for all violins
bw_adjust Bandwidth multiplier, as in kdeplot
cut=0 Stop the violin at the data limits instead of extending past them
gap, width, linewidth, saturation, palette Spacing and look

Violins can imply data where there is none: the smooth tails extend past the real minimum and maximum unless cut=0. With fewer than about 20 points per group a violin is mostly the bandwidth, so use a swarm plot instead.

Which to choose?

Need Plot
Compare medians and spreads across many groups Box
Detect multiple modes or skew Violin
Large datasets with heavy tails Boxen
Audience unfamiliar with statistics Violin with inner="point", or strip plot

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. In a standard box plot, what does the box show?

    The box spans Q1 to Q3 and the line inside is the median.
  2. 2. When is a boxenplot more informative than a boxplot?

    Boxen plots add boxes for more quantiles as the sample size grows.
  3. 3. What does split=True do in violinplot?

    It requires a hue with exactly two levels and gives a compact comparison.
  4. 4. Why use cut=0 in a violin plot?

    The KDE tails normally extend past the min and max, which can mislead for bounded data.
  5. 5. A box plot looks the same for two groups, but one is bimodal. Which would reveal it?

    Shape-aware plots show two humps that a five-number summary hides.

Summary

  • A box plot shows the median, quartile box, whiskers (1.5 x IQR by default) and outliers.
  • Boxen plots add nested quantile boxes for large samples and heavy tails.
  • Violin plots show a KDE per group; tune with inner, split, bw_adjust, cut and density_norm.
  • Use hue with gap for sub-groups; showfliers=False when overlaying points.
  • Pick the plot that matches how much shape detail your audience needs.

Next: Bar, Count and Point Plots