Customize Matplotlib X-Axis Label Color and Size in Python

An Austin coffee chain asked me to fix the Matplotlib x axis label color and size on their revenue chart, because the label vanished on a projector. You pass color and fontsize straight to xlabel().

The default label is black at 10 points, which is fine on a laptop and unreadable from the back of a meeting room.

Quick answer: set both in the same call:

ax.set_xlabel("Month", color="#6f4e37", fontsize=16)

In this tutorial, I’ll style the label with pyplot and the Axes API, change it after the fact, sort out tick colors and set report-wide defaults.

Set the x-axis label color and size with plt.xlabel()

My sample is Lone Star Coffee’s monthly revenue for January to June 2026, run on Python 3.12.5 and Matplotlib 3.11.2. With pyplot, the keywords go on plt.xlabel():

import matplotlib.pyplot as plt

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
revenue = [42.5, 47.8, 51.2, 49.6, 55.3, 58.9]   # thousand USD, 2026

plt.figure(figsize=(8, 4.5))
plt.plot(months, revenue, marker="o", color="#6f4e37")
plt.title("Lone Star Coffee - monthly revenue, 2026")
plt.xlabel("Month (2026)", color="#6f4e37", fontsize=16)
plt.ylabel("Revenue (thousand USD)")
plt.tight_layout()
plt.show()
Matplotlib line chart of Lone Star Coffee revenue with a 16 point brown x-axis label set by plt.xlabel
The Month (2026) label is brown and clearly larger than the y-axis label.

size= works as a short alias for fontsize=. For label text, position and subplots, see my full guide to the Matplotlib x-axis label.

Style the label with ax.set_xlabel() and a fontdict

In object-oriented code, use set_xlabel(). A fontdict keeps color, size and weight in one reusable place:

import matplotlib.pyplot as plt

# months and revenue from the first example

fig, ax = plt.subplots(figsize=(8, 4.5))
ax.bar(months, revenue, color="#c8a27a")
style = {"color": "darkgreen", "fontsize": "x-large",
         "fontweight": "bold"}
ax.set_xlabel("Month (2026)", fontdict=style, labelpad=10)
ax.set_ylabel("Revenue (thousand USD)")
plt.tight_layout()
plt.show()
Matplotlib bar chart with a bold dark green x-axis label sized x-large through a fontdict in set_xlabel
The x-axis label is bold, dark green and x-large, with extra space from labelpad.

Named sizes scale from the base 10 pt font, so they’ll follow your theme if you change it. To size both axis labels together, read changing the Matplotlib axis label font size.

Change the x-axis label color and size after plotting

When a helper function has already drawn your chart, you can grab the label through ax.xaxis.label. Here’s what the VS Code run printed:

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

fig, ax = plt.subplots()
ax.set_xlabel("Month (2026)")
label = ax.xaxis.label
print("before:", label.get_color(), label.get_fontsize())

label.set_color("crimson")
label.set_fontsize(14)
print("after: ", label.get_color(), label.get_fontsize())

for size in ("small", "large", "x-large"):
    label.set_fontsize(size)
    print(f"{size:>8} = {label.get_fontsize():.2f} pt")

Output:

before: black 10.0
after:  crimson 14.0
   small = 8.33 pt
   large = 12.00 pt
 x-large = 14.40 pt
VS Code output showing the Matplotlib x-axis label color and font size before and after set_color and set_fontsize
The label goes from black at 10 pt to crimson at 14 pt, and the named sizes print their point values.

So small is about 8.33 pt and x-large is 14.40 pt. If a bigger label now crowds the ticks, adjusting x-axis label spacing helps.

Why don’t tick_params colors change the x-axis label?

Same chart twice: the left panel colors the ticks, the right one colors the axis label itself:

import matplotlib.pyplot as plt

# months and revenue from the first example

fig, (left, right) = plt.subplots(1, 2, figsize=(11, 4.5))
for ax in (left, right):
    ax.plot(months, revenue, marker="o", color="#6f4e37")

left.tick_params(axis="x", colors="red")         # ticks only
left.set_xlabel("Month (2026)")
left.set_title("tick_params(colors='red')")

right.set_xlabel("Month (2026)", color="red", fontsize=14)
right.set_title("set_xlabel(color='red')")
plt.tight_layout()
plt.show()
Two Matplotlib line charts comparing tick_params colors red, which colors only the tick labels, with set_xlabel color red
On the left, only the month names turn red; on the right, the Month (2026) label does.

tick_params() styles the month names, not the axis title, so you won’t see the label change. More options are in Matplotlib tick_params(), and changing the tick label font size covers sizing them.

Set a default x-axis label color and size with rcParams

For a whole report, you can change the defaults once, and every new label you create follows them:

import matplotlib.pyplot as plt

print(plt.rcParams["axes.labelcolor"], plt.rcParams["axes.labelsize"])
plt.rcParams.update({"axes.labelcolor": "#6f4e37",
                     "axes.labelsize": 14})

fig, ax = plt.subplots()
label = ax.set_xlabel("Month (2026)")
print(label.get_color(), label.get_fontsize())

Output:

black medium
#6f4e37 14.0

Stock values are black and medium; new labels come out brown at 14 pt. Long month names may also need rotated tick labels at 45 or 90 degrees.

Common errors and how to fix them with label styling

  • ValueError: ‘blu’ is not a valid value for color: fix the typo or use a hex code like #1f77b4.
  • Setting xtick.color didn’t recolor the label: that key styles ticks; use axes.labelcolor.
  • Label cut off at the bottom: add plt.tight_layout() after enlarging it.

These Matplotlib styling guides pair well with this one:

Frequently asked questions

How do I change the x-axis label color in Matplotlib?

Pass color: ax.set_xlabel("Month", color="navy").

How do I make the x-axis label bigger?

Use fontsize=16 or a named size such as "x-large".

Can I change only the x-axis label, not the y-axis label?

Yes. Style it through set_xlabel() or ax.xaxis.label; the y label keeps its defaults.

How do I color the tick labels instead?

Use ax.tick_params(axis="x", labelcolor="red").

How do I set the label color for every chart?

Set plt.rcParams["axes.labelcolor"] and axes.labelsize once.

Where are the set_xlabel options documented?

See Axes.set_xlabel() in the Matplotlib docs.