Course contentsShow
← Data Science
Lesson 1282 of 2,14532. Visualization with Matplotlib and SeabornFree lesson

Distribution Plots: histplot and kdeplot

Visualizing univariate distributions with histograms and kernel density estimates.

Distribution Plots: histplot and kdeplot

What You'll Learn

You'll learn how to visualize the shape and spread of single variables using Seaborn's histplot and kdeplot functions.

Understanding Distribution Plots

When you want to understand how a single variable's values are distributed—where most observations cluster, whether there are peaks or gaps, and the overall shape—you need univariate distribution plots.

Seaborn provides two complementary approaches:

histplot: The Binned View

histplot() divides your data into bins (intervals) and counts how many observations fall into each bin, creating a bar chart of frequencies. It's like sorting coins into labeled jars—you see exactly how many fall into each range.

import seaborn as sns
import matplotlib.pyplot as plt

# Basic histogram
sns.histplot(data=tips, x='total_bill')
plt.show()

You can customize bin width, show density instead of counts, and even overlay multiple distributions.

kdeplot: The Smooth Curve

kdeplot() creates a kernel density estimate—a smoothed curve representing the probability density. Instead of discrete bins, it draws a continuous line showing where data is concentrated. Think of it as melting your histogram into a flowing curve that reveals the underlying shape.

# Kernel density estimate
sns.kdeplot(data=tips, x='total_bill')
plt.show()

Combining Both for Insight

Often, using both together provides the clearest picture:

# Histogram with overlaid KDE
sns.histplot(data=tips, x='total_bill', kde=True)
plt.show()

The histogram shows you exact counts and boundaries, while the KDE reveals the smooth, continuous pattern beneath the data.

Key Takeaway: Use histplot() for binned frequency counts and kdeplot() for smooth density curves to visualize how a single variable's values are distributed—they're your go-to tools for understanding univariate patterns in Seaborn.