plot customization
tick label font size
data visualization
matplotlib
graph styling

How to change tick label font size

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Matplotlib, tick label font size is controlled separately from axis titles, legends, and figure titles. The cleanest answer is usually tick_params, but there are a few related patterns depending on whether you want to style one axis, both axes, or all plots globally.

The Most Direct Method: tick_params

For one axes object, this is usually the best solution.

python
1import matplotlib.pyplot as plt
2
3fig, ax = plt.subplots()
4ax.plot([1, 2, 3], [1, 4, 9])
5ax.tick_params(axis="both", labelsize=14)
6plt.show()

axis="both" changes both x and y tick labels. You can target only one axis with axis="x" or axis="y".

Change X and Y Separately

If you want different font sizes on each axis, set them independently.

python
1import matplotlib.pyplot as plt
2
3fig, ax = plt.subplots()
4ax.plot([1, 2, 3], [1, 4, 9])
5ax.tick_params(axis="x", labelsize=10)
6ax.tick_params(axis="y", labelsize=16)
7plt.show()

That is useful when one axis contains dense categories and the other needs stronger emphasis.

Style Existing Tick Labels Directly

You can also modify the tick label text objects themselves.

python
1import matplotlib.pyplot as plt
2
3fig, ax = plt.subplots()
4ax.plot([1, 2, 3], [1, 4, 9])
5
6for label in ax.get_xticklabels():
7    label.set_fontsize(12)
8
9for label in ax.get_yticklabels():
10    label.set_fontsize(12)
11
12plt.show()

This approach is more verbose but gives you per-label control when needed.

Set a Global Default

If you want all figures in a script or notebook to use the same tick label size, update rcParams.

python
1import matplotlib.pyplot as plt
2
3plt.rcParams["xtick.labelsize"] = 12
4plt.rcParams["ytick.labelsize"] = 12
5
6fig, ax = plt.subplots()
7ax.plot([1, 2, 3], [1, 4, 9])
8plt.show()

That is useful for reports or dashboards where consistent styling matters across many plots.

Tick Labels Versus Axis Labels

The pyplot Shortcut

If you are working in a quick script without keeping an Axes reference, plt.xticks and plt.yticks can also change tick label size. It is less explicit than ax.tick_params, but it is common in short notebook examples.

python
1import matplotlib.pyplot as plt
2
3plt.plot([1, 2, 3], [1, 4, 9])
4plt.xticks(fontsize=12)
5plt.yticks(fontsize=12)
6plt.show()

A common source of confusion is mixing up tick labels with axis labels.

  • tick labels are the numbers or categories along the axis
  • axis labels are the descriptive titles such as “Time” or “Revenue”

Axis labels are changed separately.

python
ax.set_xlabel("Time", fontsize=14)
ax.set_ylabel("Value", fontsize=14)

Changing axis-label font size does not affect tick-label font size.

Layout Matters Too

Larger tick labels can overlap or get clipped. If you increase font size, you may also need to adjust layout.

python
plt.tight_layout()

This is especially important in notebooks, saved figures, or rotated category labels.

Common Pitfalls

The most common mistake is changing axis-label font size and expecting tick labels to change with it.

Another mistake is setting large tick fonts without adjusting layout, which often leads to clipped text or overlapping labels.

Developers also sometimes use global rcParams for a one-off figure and then wonder why later plots inherit the same styling unexpectedly.

Summary

  • Use ax.tick_params(labelsize=...) for the simplest per-plot solution.
  • You can style x and y tick labels separately.
  • Use direct label objects only when you need fine-grained control.
  • Use rcParams for global defaults across many plots.
  • Bigger tick labels often require layout adjustments such as tight_layout().

If category labels are long, you may also need to rotate them so the larger font remains readable. Small typography changes often require a matching spacing change in the figure.

python
plt.xticks(rotation=45, fontsize=12)
plt.tight_layout()

Course illustration
Course illustration

All Rights Reserved.