Histograms & Box Plots

When analyzing a dataset, understanding how values are distributed is often more informative than just looking at averages. Two fundamental visualization tools for this are histograms and box plots. These plots reveal patterns, concentrations, and anomalies in your data that simple summary statistics might miss, providing a quick visual assessment of a variable's characteristics.

Visualizing Distributions with Histograms

A histogram provides a visual representation of the distribution of a continuous variable. It groups data into a series of intervals, called bins, and then counts how many data points fall into each bin. The height of each bar in the histogram corresponds to the frequency (or count) of observations within that specific bin, allowing you to quickly see where data values are concentrated and how they spread out.

Histogram
A graphical display of the distribution of a continuous dataset, showing the frequency of data points falling into defined numerical ranges (bins).
Example: A histogram of employee salaries might show that most employees earn between 50K and 70K, with fewer earning above 100K.

Building a Histogram: Bins and Counts

The construction of a histogram hinges on defining appropriate bins. Each bin represents a range of values, and all bins must be contiguous and cover the entire range of the data. The bin width significantly impacts the histogram's appearance: too few bins can obscure important details, while too many can make the plot noisy and difficult to interpret. Most plotting libraries offer automatic bin selection, but manual adjustment is often necessary for optimal insight.

pythonGenerating a Histogram of Customer Spending
✨ Choosing Bin Width

The optimal number of bins is often a balance. Rules like Sturges' formula (k=1+log⁡2Nk = 1 + \log_2 N) or Freedman-Diaconis rule can provide a starting point, but visual inspection and domain knowledge are crucial. Experiment with different bin counts to find the most informative view of your data.

Interpreting Histogram Shapes

The shape of a histogram tells a story about the underlying data distribution. A symmetric distribution, like a normal distribution, has a bell shape where both sides are roughly mirror images. Skewed distributions are asymmetrical; a right-skewed (positively skewed) distribution has a long tail extending to the right, indicating a few high values, while a left-skewed (negatively skewed) distribution has a long tail to the left. You might also observe bimodal distributions with two distinct peaks, suggesting two different groups within your data.

Example of a Right-Skewed Distribution
This histogram illustrates a right-skewed distribution, where the bulk of the data is concentrated on the left side, and a longer tail extends towards higher values. This pattern is common in data like income or housing prices, where a few observations have significantly larger values.
Loading chart...
Key Insight: A right-skewed histogram indicates that most values are lower, with a few higher values pulling the mean to the right of the median.
Check Your Understanding
What happens to a histogram's appearance if you significantly increase the number of bins for the same dataset?

Summarizing Distributions with Box Plots

While histograms show the full shape of a distribution, box plots (also known as box-and-whisker plots) offer a concise summary of its central tendency, spread, and potential outliers. They are particularly useful for comparing distributions across multiple groups or categories, as they distill key statistical measures into a compact visual. A box plot highlights the median, quartiles, and the range of typical data, making it easy to spot skewness and extreme values.

Box Plot
A standardized way of displaying the distribution of data based on a five-number summary: minimum, first quartile (Q1), median (Q2), third quartile (Q3), and maximum, often with explicit outlier representation.
Example: A box plot of exam scores might show that the middle 50% of students scored between 70 and 85, with a few students scoring below 40 (outliers).

The Five-Number Summary

Every box plot is built upon the five-number summary, which consists of the minimum value, the first quartile (Q1), the median (Q2), the third quartile (Q3), and the maximum value. These five statistics divide the data into four equal parts, each containing 25% of the observations. The median represents the 50th percentile, Q1 the 25th percentile, and Q3 the 75th percentile, providing a robust measure of central tendency and spread that is less sensitive to extreme values than the mean and standard deviation.

📐 Interquartile Range (IQR)

The Interquartile Range (IQR) is a measure of statistical dispersion, representing the range of the middle 50% of the data. It is calculated as the difference between the third quartile (Q3) and the first quartile (Q1):

IQR=Q3−Q1IQR = Q3 - Q1

Constructing a Box Plot: IQR and Outlier Detection

The 'box' in a box plot extends from Q1 to Q3, with a line inside marking the median. The 'whiskers' extend from the box to the minimum and maximum values within a certain range, typically 1.5×IQR1.5 \times IQR from Q1 and Q3. Any data points falling outside these whiskers are considered outliers and are plotted individually. This standardized method provides a clear visual distinction between the bulk of the data and unusually extreme observations.

pythonCreating a Box Plot of Exam Scores

Interpreting Box Plots: Skewness and Outliers

Box plots offer quick visual cues for skewness: if the median line is closer to Q1, or the lower whisker is shorter, the data is likely right-skewed. Conversely, if the median is closer to Q3, or the upper whisker is shorter, it suggests left-skewness. The presence of individual points beyond the whiskers immediately highlights potential outliers, prompting further investigation. Comparing the lengths of the box and whiskers across multiple plots quickly reveals differences in data spread and central tendency between groups.

Comparing Distributions with Box Plots
This chart displays three box plots, each representing a different data distribution. 'Symmetric' shows a balanced distribution, 'Right Skew' indicates a longer tail towards higher values, and 'Outliers' highlights extreme data points beyond the whiskers.
Loading chart...
Key Insight: Box plots quickly reveal differences in median, interquartile range, and the presence of outliers across multiple groups, making comparisons efficient.
Check Your Understanding
If a box plot's median line is significantly closer to its Q1 than its Q3, what does this suggest about the data?

Choosing the Right Plot: Histograms vs. Box Plots

Deciding between a histogram and a box plot depends on your analytical goal. Histograms excel at showing the precise shape and modality of a single distribution, revealing nuances like multiple peaks or gaps in the data. Box plots, on the other hand, are superior for comparing the central tendency, spread, and outlier presence across several groups simultaneously. They offer a more compact summary, sacrificing some detail about the exact shape for efficient comparison.

Histograms vs. Box Plots
FeatureHistogramBox Plot
Primary PurposeShow detailed shape of a single distributionSummarize central tendency, spread, and outliers for comparison
Detail LevelHigh: shows individual bins and modalityLow: five-number summary, hides exact shape
Outlier VisibilityImplied by long tails or isolated barsExplicitly marked as individual points
Comparison of GroupsDifficult for more than 2-3 groups (requires multiple plots)Excellent for comparing many groups side-by-side
Best Use CaseExploring the full distribution of a single variableComparing key statistics across multiple categories
A guide to when to use histograms versus box plots based on analytical needs.

Combining Visualizations for Deeper Insight

Often, the most powerful insights come from using both histograms and box plots together. A histogram provides the granular view of the distribution's shape, while a box plot offers a concise summary and highlights outliers. For instance, you might use a histogram to understand the overall pattern of customer ages, then use a box plot to compare age distributions across different customer segments. This combined approach leverages the strengths of each visualization, providing a more complete understanding of your data.

pythonVisualizing Data with Both Histogram and Box Plot
Try It Yourself
Modify the review_scores generation in the code example above to create a right-skewed distribution (e.g., by changing loc and scale or adding lower outliers). Observe how both the histogram and box plot change to reflect the new skewness.
python
This exercise uses a charting library (e.g. seaborn, plotly) that the in-browser runner can't display — it shows text output only. Google Colab renders plots inline, so you can run this and actually see the figures there.
Expected
You should see the histogram's peak shift left with a tail to the right, and the box plot's median line move closer to Q1, indicating right-skewness. The upper whisker might also be longer.
Key Takeaways
  • Histograms visualize the frequency distribution of continuous data, using bins to show where values are concentrated and how they spread.

  • The choice of bin width is critical for histograms; too few or too many bins can obscure or overemphasize data patterns.

  • Box plots summarize data using a five-number summary (min, Q1, median, Q3, max), providing a compact view of central tendency and spread.

  • Outliers in box plots are explicitly marked as points beyond the whiskers, which typically extend 1.5×IQR1.5 \times IQR from the quartiles.

  • Histograms are best for understanding the detailed shape and modality of a single distribution, while box plots excel at comparing key statistics across multiple groups.

  • Both plots offer visual cues for skewness: histograms show tail direction, and box plots show median position relative to quartiles and whisker lengths.

← All lessons in Descriptive Statistics

Ready to keep this from fading?

Bitelrn turns lessons like this into a full course — quizzes, a knowledge map, and spaced review.

Get started free