Rug plot

Seaborn basics

2 min read

Published Oct 7 2025


24
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonSeabornVisualisation

seaborn.rugplot() draws small tick marks (rugs) along an axis to represent individual data points.

Each tick represents one observation — giving a sense of the distribution of data along a single dimension.

It’s often used:

  • On its own for simple data density visualisation, or
  • As an addition to other plots (e.g., histplot(), kdeplot()) to show the actual observations behind a smooth curve.

Syntax:

sns.rugplot(
    data=None,
    *,
    x=None,
    y=None,
    hue=None,
    height=0.025,
    expand_margins=True,
    palette=None,
    linewidth=None,
    alpha=None,
    ax=None,
    **kwargs
)

Parameters:

  • data = DataFrame containing the data
  • x, y = Variables to plot (usually one)
  • hue = Adds subgroups (coloured rugs)
  • height = Length of each rug line (fraction of axis)
  • expand_margins = Expands axis limits to fit the rugs
  • palette = Colour palette for hue groups
  • linewidth = Thickness of each rug tick
  • alpha = Transparency (0–1)
  • ax = Axis to plot on (if combining with other plots)




Basic example

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.rugplot(data=tips, x="total_bill")
plt.show()

Each small vertical tick represents one observation of total_bill. The density of ticks gives a quick sense of data concentration.


seaborn rug plot basic example





Horizontal orientation

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.rugplot(data=tips, y="total_bill")
plt.show()

Plots rug ticks along the y-axis instead of x.


seaborn rug plot horizontal example





Add hue (subgroups)

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.rugplot(data=tips, x="total_bill", hue="sex", palette="Set2")
plt.show()

Different colours represent different categories (e.g., Male vs. Female). Overlapping colours show how groups overlap in data distribution.


seaborn rug plot hue example





Customize rug appearance

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.rugplot(
    data=tips,
    x="total_bill",
    height=0.05,
    linewidth=2,
    alpha=0.7,
    color="darkred"
)
plt.show()

Taller and thicker ticks make the rug more visible.


seaborn rug plot style example





Overlay rug on other plots


On a Histogram:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.histplot(data=tips, x="total_bill", bins=20, color="skyblue")
sns.rugplot(data=tips, x="total_bill", color="black")
plt.show()

The rugplot shows exact data points below the histogram bars.


seaborn rug plot histogram example


On a KDE Plot:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.kdeplot(data=tips, x="total_bill", fill=True, color="lightgreen")
sns.rugplot(data=tips, x="total_bill", color="black")
plt.show()

Combines smooth distribution (KDE) with exact data locations (rug).


seaborn rug plot kde example





Bivariate rugplot (x and y)

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.rugplot(data=tips, x="total_bill", y="tip")
plt.show()

Adds small ticks on both the x- and y-axes, showing marginal distributions.


seaborn rug plot both axis example





Hue with multiple variables

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.rugplot(data=tips, x="total_bill", y="tip", hue="sex", palette="Set1", alpha=0.6)
plt.show()

Coloured rugs along both axes for each group.


seaborn rug plot both axis hue example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact