Coding⏱️ 2 min read📅 2026-05-30

How to Fix: Changing the tick frequency on the x or y axis

Change x-axis tick frequency in matplotlib plot

Quick Answer: Use the 'xticks' function to set the tick interval, e.g. plt.xticks(x, ['0', '5', '10', '15'])

To change the tick frequency on the x or y axis in matplotlib, you can use the xticks function. By default, matplotlib automatically selects the best interval for the ticks based on the data range.

🔧 Proven Troubleshooting Steps

Method 1: Using the xticks Function

  1. Step 1: Import the matplotlib library and plot your data as usual.
  2. Step 2: Use the xticks function to specify the tick locations. For example, if you want to show intervals of 1 on the x-axis, use xticks(range(0, max(x), 1)).

Example Code:

x = [0, 5, 9, 10, 15]

y = [0, 1, 2, 3, 4]

x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]
import matplotlib.pyplot as plt
x = [0, 5, 9, 10, 15]
y = [0, 1, 2, 3, 4]
plt.plot(x, y)
plt.xticks(range(0, max(x), 1))

plt.show()

🎯 Final Words

By using the xticks function, you can customize the tick frequency on your plot and make it more informative.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions