0Pricing
Pandas & NumPy Academy · Lesson

Distribution Plots: histplot and kdeplot

Visualise the shape of a numeric distribution with sns.histplot and overlay a kernel density estimate with sns.kdeplot.

Seaborn and Distribution Plots

Seaborn is a statistical data visualisation library built on top of Matplotlib. It provides a high-level API that makes beautiful, informative plots with minimal code. One of the first things you want to understand about any dataset is the shape of its distributions — and Seaborn's histplot and kdeplot are the primary tools for this.

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

# Load a built-in dataset
tips = sns.load_dataset('tips')
print(tips.head())

Creating a Basic Histogram with histplot

sns.histplot(data, x='column') creates a histogram of a numeric variable. Seaborn automatically chooses sensible bin counts using Sturges' rule by default. You can customise the number of bins with the bins parameter, or let Seaborn pick automatically. The height of each bar represents the count of observations in that range.

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset('tips')

# Basic histogram of total bill amounts
sns.histplot(data=tips, x='total_bill')
plt.title('Distribution of Total Bill')
plt.xlabel('Total Bill ($)')
plt.show()

All lessons in this course

  1. Distribution Plots: histplot and kdeplot
  2. Categorical Plots: boxplot, barplot, violinplot
  3. Scatter Plots and Pair Plots
  4. Heatmaps for Correlation Matrices
← Back to Pandas & NumPy Academy