Matplotlib Axis Label Font Size

When I first started building data visualizations in Python, I often found myself squinting at the screen. The default plots were great, but the axis labels were almost always too small to read once I put them into a presentation.

It took me some time to realize that Matplotlib gives you total control over typography. You don’t have to settle for tiny text that your audience can’t see.

In this tutorial, I will show you exactly how to change the axis label font size in Matplotlib using the same methods I use in my professional projects.

Method 1: Use the fontsize Parameter in xlabel and ylabel

This is the most direct way to get the job done. If you just need a quick fix for a single plot, you can pass the fontsize argument directly into your label functions.

I prefer this method when I’m working on a one-off chart and want different sizes for the X and Y axes.

import matplotlib.pyplot as plt

# Monthly Average Temperature in New York City (Fahrenheit)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
temp = [33, 35, 42, 53, 63, 72, 77, 76, 68, 57, 47, 38]

plt.plot(months, temp, marker='o', color='tab:blue')

# Setting axis labels with custom font sizes
plt.xlabel('Month of the Year', fontsize=14)
plt.ylabel('Temperature (°F)', fontsize=12)
plt.title('Average NYC Temperature (2023)', fontsize=16)

plt.show()

I executed the above example code and added the screenshot below.

Matplotlib Axis Label Font Size

In the code above, I set the X-axis label to 14 points and the Y-axis to 12. It’s simple, readable, and works every time.

Method 2: Use the set_xlabel and set_ylabel Methods (Object-Oriented)

When I build more complex dashboards with multiple subplots, I always use the object-oriented approach. Instead of using plt.xlabel, you call set_xlabel on the specific axes object.

This is a cleaner way to write code when you are managing several different charts in the same figure.

import matplotlib.pyplot as plt

# US Gas Prices Example (Average Price per Gallon)
years = [2019, 2020, 2021, 2022, 2023]
prices = [2.60, 2.17, 3.01, 3.95, 3.52]

fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(years, prices, color='green', linewidth=2)

# Using the axes object to set font size
ax.set_xlabel('Calendar Year', fontsize=15)
ax.set_ylabel('Price in USD ($)', fontsize=15)
ax.set_title('Average US Gas Price Trends', fontsize=18)

plt.show()

I executed the above example code and added the screenshot below.

Python Matplotlib Axis Label Font Size

I like this method because it makes it very clear which plot you are modifying.

Method 3: Change Font Size Globally with rcParams

If you are creating ten different charts for a US Census report, you don’t want to type fontsize=14 ten times. This is where rcParams comes in handy.

I use this to set a “theme” at the beginning of my script. It tells Matplotlib to use these sizes for every plot I create afterward.

import matplotlib.pyplot as plt

# Setting global font sizes for the entire script
plt.rcParams.update({'axes.labelsize': 18, 'axes.titlesize': 22})

# California vs Texas Population Growth (Millions)
years = [2010, 2020]
ca_pop = [37.3, 39.5]
tx_pop = [25.1, 29.1]

plt.bar(['California', 'Texas'], [39.5, 29.1], color=['blue', 'orange'])

# Labels will automatically use size 18 from rcParams
plt.xlabel('State')
plt.ylabel('Population (Millions)')
plt.title('Current Population Comparison')

plt.show()

I executed the above example code and added the screenshot below.

Matplotlib Axis Label Font Size using Python

This is a massive time-saver. Just remember that this affects every plot in your session until you restart your Python kernel.

Method 4: Use a Font Dictionary (fontdict)

Sometimes I want to change the font size, color, and weight (boldness) all at once. Instead of passing five different arguments to xlabel, I create a dictionary.

It keeps the code organized and makes it easy to reuse the same style across different labels.

import matplotlib.pyplot as plt

# Tech Stock Performance (NVIDIA Market Cap in Trillions)
quarters = ['Q1', 'Q2', 'Q3', 'Q4']
market_cap = [1.2, 1.5, 2.1, 2.3]

# Defining a reusable font style
label_style = {
    'family': 'serif',
    'color':  'darkred',
    'weight': 'bold',
    'size': 14,
}

plt.plot(quarters, market_cap, marker='s', color='black')

# Applying the fontdict to labels
plt.xlabel('Fiscal Quarter', fontdict=label_style)
plt.ylabel('Market Cap (Trillions USD)', fontdict=label_style)
plt.title('NVDA Growth Performance', fontsize=18)

plt.show()

This is particularly useful when you’re following a specific branding guide for a company presentation.

A Note on Tick Labels

Keep in mind that “axis labels” (like “Price”) are different from “tick labels” (the numbers like “1, 2, 3”). If you want to change the size of the numbers on the axis, you should use plt.xticks(fontsize=12).

Adjusting the font size is one of the easiest ways to make your Python charts look professional. Whether you use a quick parameter or a global setting, your readers will thank you for the clarity.

You may read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.