HOWTO · Seaborn

How to Add Axis Labels to Seaborn Plot

Set x- and y-axis labels on Seaborn plots with Axes methods or Matplotlib pyplot, and customize their appearance.

On this page

To add or replace axis labels on a Seaborn plot, call set_xlabel() and set_ylabel() on the Matplotlib Axes object returned by the plotting function. Seaborn often derives default labels from the variables mapped to x and y, but the exact defaults depend on the plot and its inputs. Set the labels explicitly when you need reader-facing names.

Use Axes.set_xlabel() and Axes.set_ylabel()

This approach targets the specific axes returned by Seaborn, so it works clearly when a figure contains more than one plot. The example uses a small in-memory dataset and prints the labels after setting them.

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import seaborn as sns

days = ["Mon", "Tue", "Wed"]
orders = [12, 18, 15]
ax = sns.lineplot(x=days, y=orders, marker="o")
ax.set_xlabel("Day", fontsize=12)
ax.set_ylabel("Orders", fontsize=12)
print(ax.get_xlabel(), "|", ax.get_ylabel())
plt.close()

Seaborn line plot with axis labels Day and Orders

fontsize and color are useful text properties to adjust label appearance; for example, pass color="navy" to either method. These calls change the axis labels, while a title is separate: use ax.set_title("Orders by day") when a title is needed. If tick labels crowd the axis, rotate them with ax.tick_params(axis="x", labelrotation=45) or give the figure more room with fig, ax = plt.subplots(figsize=(8, 4)) before creating the plot on that axes.

Set both labels with Axes.set()

Use set() when setting both labels on the same Axes object. Its xlabel and ylabel keyword arguments make the two changes together; keep the returned axes in a variable so the target is explicit.

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import seaborn as sns

months = ["Jan", "Feb", "Mar"]
visitors = [120, 145, 138]
ax = sns.lineplot(x=months, y=visitors, marker="o")
ax.set(xlabel="Month", ylabel="Visitors")
print(ax.get_xlabel(), "|", ax.get_ylabel())
plt.close()

Seaborn line plot with axis labels Month and Visitors

Set labels with matplotlib.pyplot.xlabel() and matplotlib.pyplot.ylabel()

The matplotlib.pyplot.xlabel() and matplotlib.pyplot.ylabel() functions are convenient in a simple script that works with one current axes. They act on pyplot’s current axes, so select the intended axes first if a figure has several plots. The example makes the Seaborn axes current before applying the labels.

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import seaborn as sns

products = ["A", "B", "C"]
sales = [8, 13, 10]
ax = sns.barplot(x=products, y=sales)
plt.sca(ax)
plt.xlabel("Product", fontsize=12)
plt.ylabel("Sales", fontsize=12)
print(ax.get_xlabel(), "|", ax.get_ylabel())
plt.close()

Seaborn bar plot with axis labels Product and Sales

For a single plot, either API can set labels; prefer the Axes methods when the plot object is already available or when managing multiple axes. Use pyplot when its current-axes model fits the surrounding code. To add grid lines, call ax.grid(True) on the intended axes.