Histograms and Distribution Plots
What you'll learn: How to visualize the distribution of continuous data using histograms, control binning strategies, and overlay density curves to better understand your data's shape and characteristics.
The Core Idea
A histogram divides continuous data into bins (intervals) and counts how many observations fall into each bin, displaying this as bars. Unlike bar plots that compare categories, histograms reveal the distribution shape of numeric data—showing you where values cluster, how spread out they are, and whether patterns like skewness or multiple peaks exist.
Think of a histogram like sorting coins into cups by value ranges: pennies in one cup, nickels in another. The height of coins in each cup shows you which values are most common.
Controlling Bins
The number of bins dramatically affects what you see:
- Too few bins: You lose detail and may miss important patterns
- Too many bins: The plot becomes noisy and hard to interpret
- Just right: Reveals the true distribution shape clearly
Matplotlib lets you specify bins as a number (bins=20) or custom edges (bins=[0, 10, 25, 50, 100]).
Density Curves and KDE Overlays
Beyond raw counts, you can normalize histograms to show density (area sums to 1), making it easier to compare distributions of different sizes. Overlaying a KDE (Kernel Density Estimate) adds a smooth curve that estimates the underlying probability distribution, helping you see trends the blocky bins might obscure.
This combination—histogram bars for concrete counts plus a smooth KDE line—gives both precision and intuition about your data's distribution.
Practical Use in Exploration
Histograms answer questions like: Is this variable normally distributed? Are there outliers? Should I transform this before modeling? They're essential for initial data exploration and assumption checking.
Key Takeaway: Histograms reveal the distribution shape of continuous variables through binned counts; control bin size carefully and overlay density curves or KDE to balance detail with interpretability during data exploration.