Skip to Content

Remove Tick Labels from a Plot in Matplotlib

In this tutorial, we will look at how to remove the tick labels from a matplotlib plot with the help of some examples.

Hide Tick Labels and Ticks in a Plot

If you’re working with a single plot, then you can use the matplotlib.pyplot.tick_params() function to hide or remove ticks and/or tick labels from one or both axes.

  • To remove the tick labels from the x-axis, pass labelbottom=False and to remove the tick labels from the y-axis, pass labelleft=False as an argument to the tick_params() function.
  • To remove the ticks from the x-axis, pass bottom=False and to remove the ticks from the y-axis, pass left=False as an argument to the tick_params() function.

Let’s now look at some examples of using the above syntax. First, we will create a scatter plot that we will be using throughout this tutorial.

import matplotlib.pyplot as plt

# x values - years
x = [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020]
# y values - 1 USD in INR
y = [46.67, 53.44, 56.57, 62.33, 62.97, 66.46, 67.79, 70.09, 70.39, 76.38]

# plot x and y on scatter plot
plt.scatter(x, y)

# add axes labels
plt.xlabel('Year')
plt.ylabel('1USD in INR')

Output:

scatter plot with default tick and tick labels

You can see that the ticks on the x-axis and the y-axis are labeled.

Example 1 – Remove Tick Labels from the Plot

Let’s now hide the ticks on the x-axis. To remove the x-axis labels, pass labelbottom=False as an argument to the tick_params() function. This argument essentially tells the function to not show the tick labels of the bottom axis (x-axis).

# plot x and y on scatter plot
plt.scatter(x, y)

# add axes labels
plt.xlabel('Year')
plt.ylabel('1USD in INR')

# hide the x-axis tick labels
plt.tick_params(labelbottom=False)

Output:

x axis tick labels removed

You can similarly remove the y-axis tick labels by passing labelleft=False to the tick_params() function.

# plot x and y on scatter plot
plt.scatter(x, y)

# add axes labels
plt.xlabel('Year')
plt.ylabel('1USD in INR')

# hide the y-axis tick labels
plt.tick_params(labelleft=False)

Output:

y axis tick labels removed

The y-axis tick labels are not present in the above plot.

Note that you can similarly remove the tick labels from both the x-axis and the y-axis together by passing labelbottom=False and labelleft=False as arguments.

Example 2 – Remove Ticks from a Plot

You can also use the plt.tick_params() function to remove the ticks on the plot. Pass bottom=False to remove the ticks from the x-axis and pass bottom=True to remove the ticks from the y-axis.

Let’s remove the x-axis ticks.

# plot x and y on scatter plot
plt.scatter(x, y)

# add axes labels
plt.xlabel('Year')
plt.ylabel('1USD in INR')

# hide the x-axis ticks
plt.tick_params(bottom=False)

Output:

x axis ticks removed

Let’s now remove the y-axis ticks.

# plot x and y on scatter plot
plt.scatter(x, y)

# add axes labels
plt.xlabel('Year')
plt.ylabel('1USD in INR')

# hide the y-axis ticks
plt.tick_params(left=False)

Output:

y axis ticks removed

Example 3 – Putting it all together

In our final example, let’s remove the tick labels and the ticks from both the x-axis and the y-axis for the above scatter plot.

# plot x and y on scatter plot
plt.scatter(x, y)

# add axes labels
plt.xlabel('Year')
plt.ylabel('1USD in INR')

# hide the ticks and tick labels for both the axes
plt.tick_params(left=False, bottom=False, labelleft=False, labelbottom=False)

Output:

ticks and tick labels removed from both the axes

Both the ticks and the labels are removed.

You might also be interested in –


Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


Author

  • Piyush

    Piyush is a data scientist passionate about using data to understand things better and make informed decisions. In the past, he's worked as a Data Scientist for ZS and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.