I’ve come to appreciate how small details can make a big difference in the clarity and professionalism of a plot. One such detail is controlling the ticks on your Matplotlib charts. If you’ve ever struggled with overlapping tick labels or unclear axis markings, you’re not alone.
In this article, I’ll share practical ways to use Matplotlib’s tick_params function to customize tick marks and labels effectively.
Let’s get in!
What is tick_params in Matplotlib?
tick_params is a versatile function in Matplotlib that lets you customize the appearance and behavior of ticks on both the x-axis and y-axis. You can control the direction, size, color, width, and visibility of ticks and tick labels with a single call.
This function is beneficial when default ticks clutter your plot or when you want to emphasize certain parts of your data.
How to Use tick_params: Step-by-Step
I’ll walk you through several common scenarios I encounter and how I solve them with tick_params.
1. Change Tick Direction and Size
By default, ticks point outward. Sometimes, inward ticks look cleaner, especially in dense plots.
import matplotlib.pyplot as plt
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [25000, 27000, 30000, 28000, 32000, 31000]
plt.plot(months, sales)
plt.tick_params(axis='x', direction='in', length=10, width=2)
plt.tick_params(axis='y', direction='inout', length=8, width=1.5)
plt.title('Monthly Sales Data - NYC Retail Chain')
plt.show()I executed the above example code and added the screenshot below.

Here, I set x-axis ticks to point inward with a length of 10 points and a thicker width for emphasis. The y-axis ticks point both inward and outward (inout), giving a balanced look.
2. Control Tick Color and Width
Highlighting ticks can guide viewers’ attention.
plt.plot(months, sales)
plt.tick_params(axis='x', colors='red', width=2)
plt.tick_params(axis='y', colors='blue', width=1)
plt.title('Monthly Sales Data with Colored Ticks')
plt.show()I executed the above example code and added the screenshot below.

Red x-axis ticks stand out, making it easy to associate tick marks with month labels.
Check out Python Plot Multiple Lines Using Matplotlib
3. Hide Ticks or Tick Labels
Sometimes, you want to remove ticks or labels to reduce clutter.
plt.plot(months, sales)
plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=True)
plt.tick_params(axis='y', which='major', left=False, labelleft=True)
plt.title('Clean Plot Without Y-axis Ticks')
plt.show()I executed the above example code and added the screenshot below.

In this example, I hide y-axis major ticks but keep their labels visible, which can be useful when you want a minimalist look but still need scale references.
4. Differentiate Major and Minor Ticks
If you use minor ticks for finer granularity, you can style them separately.
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.minorticks_on()
ax.tick_params(axis='x', which='major', length=10, width=2, color='black')
ax.tick_params(axis='x', which='minor', length=5, width=1, color='gray')
ax.tick_params(axis='y', which='major', length=8, width=1.5, color='black')
ax.tick_params(axis='y', which='minor', length=4, width=1, color='gray')
plt.title('Sine Wave with Major and Minor Ticks')
plt.show()This approach makes your plot more informative by visually distinguishing tick importance.
5. Rotate Tick Labels for Better Fit
Long labels can overlap, especially on the x-axis, with categorical data like US state names.
states = ['California', 'Texas', 'New York', 'Florida', 'Illinois']
values = [39500000, 29000000, 19500000, 21500000, 12500000]
plt.bar(states, values)
plt.tick_params(axis='x', rotation=45)
plt.title('Population by State')
plt.show()Note: While tick_params doesn’t rotate labels directly, you can combine it with plt.xticks(rotation=45) for label rotation.
Read What is Matplotlib Inline in Python
Tips from My Experience
- Always specify the
axisparameter ('x','y', or'both') to avoid unintended changes. - Use
whichto target'major','minor', or'both'ticks. - Combine
tick_paramswith other functions likeset_xticklabelsorset_yticklabelsfor advanced label formatting. - For interactive plots, changing tick parameters dynamically can improve the user experience.
Customizing ticks with Matplotlib’s tick_params is a simple yet powerful way to polish your visualizations. Whether you’re preparing sales reports for a US-based business or analyzing climate data across states, fine-tuning ticks ensures your charts communicate clearly and professionally.
I encourage you to experiment with the parameters and find the style that best fits your data story. If you’re new to Matplotlib, mastering tick_params early will save you time and elevate your plots.
You may like to read:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.