Histogram
Seaborn basics
2 min read
This section is 2 min read, full guide is 42 min read
Published Oct 7 2025
Log in to enable the "Like" button
Log in to enable the "Save" button
Share or download this guide
ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation
seaborn.histplot() visualises the distribution of one or two numerical variables using histograms (and optionally KDE curves).
Syntax:
sns.histplot(
data=None,
x=None,
y=None,
hue=None,
stat="count",
bins="auto",
binwidth=None,
discrete=False,
cumulative=False,
common_bins=True,
common_norm=True,
multiple="layer",
element="bars",
fill=True,
shrink=1,
kde=False,
palette=None,
ax=None,
**kwargs
)
Parameters:
data = DataFrame containing datax, y = Variables for histogram axeshue = Colour by categorystat = What the height of bars represents: "count", "frequency", "probability", "percent", "density"bins = Number of bins or bin edgesbinwidth = Width of each binmultiple = How hue groups are displayed ("layer", "stack", "dodge", "fill")element = "bars", "step", or "poly" for different visual stylesfill = Whether to fill the barskde = Add a kernel density estimate curvepalette = Colour schemediscrete = If True, treats x as categorical/discrete valuescumulative = If True, shows cumulative countsshrink = Adjusts bar width when multiple hue categories are used
Basic example
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill")
plt.show()
Creates a simple histogram showing how total_bill values are distributed.
Add a KDE curve (smoothed distribution)
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", kde=True)
plt.show()
Adds a smooth density curve to visualise the probability distribution.
Color by category (hue)
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", hue="sex", palette="Set2")
plt.show()
Different colours for each group (male vs. female).
Display hue groups separately
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(
data=tips,
x="total_bill",
hue="sex",
multiple="dodge",
shrink=0.8,
palette="pastel"
)
plt.show()
Options for multiple:
"layer" = Overlays bars (default)"dodge" = Side-by-side bars"stack" = Stacks bars on top of each other"fill" = Stacks but normalises to 100% height
Adjust number or width of bins
Control how detailed the histogram is.
Number of bins:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", bins=20)
plt.show()
Width of bins:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", binwidth=5)
plt.show()
Normalise or change stat type
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", stat="percent", bins=20)
plt.show()
Bar height shows percentages instead of raw counts.
Options for stat:
"count" (default)"frequency""probability""percent""density"
2D histogram (Bivariate Distribution)
You can plot two numeric variables with both x and y.
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", y="tip")
plt.show()
Creates a 2D histogram (heatmap-like) plot showing joint frequency.
Add hue with 2D data
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", y="tip", hue="sex", palette="coolwarm")
plt.show()
Adds color separation by category.
Change style
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(
data=tips,
x="total_bill",
hue="sex",
element="step",
fill=False,
palette="Set1"
)
plt.show()
Options for element:
"bars" = Default filled bars"step" = Outlined (no fill)"poly" = Polygon-style shape
Discrete variable histogram
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="size", discrete=True)
plt.show()
Ensures each category/bin is represented individually.
Cumulative distribution
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", cumulative=True)
plt.show()
Bars accumulate counts progressively from left to right.
Logarithmic scale
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", log_scale=True)
plt.show()
Useful when data spans several orders of magnitude.
Combine with KDE plot for clarity
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.histplot(data=tips, x="total_bill", kde=True, bins=20, color="skyblue")
plt.show()
Combines discrete histogram bars and smooth density curve.