The Wayback Machine - https://web.archive.org/web/20240625002401/https://www.geeksforgeeks.org/how-to-remove-ticks-from-matplotlib-plots/
Open In App

How to Remove Ticks from Matplotlib Plots?

Last Updated : 24 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Matplotlib is a Python library that offers us various functions using which we can plot our data and visualize it graphically. But often plotting a graph using the Matplotlib library, we get ticks in our plot which are marked by default on both sides of the plot on the x and y-axis. There can be cases when we don’t want to show these ticks in our plot. Matplotlib.pyplot library offers us a tick_params() method using which we can remove these ticks manually.

The tick_params() function accepts some attributes that take Boolean values which can be used to remove ticks and labels on the plot.  By default, the values in this attribute are set to True,

Let’s understand this using an example:

Python




# importing matplotlib library
import matplotlib.pyplot as plt
  
# making points to be plotted on x-axis and y-axis
X_axis = [i for i in range (10, 110, 10)]
Y_axis = [2*j+5 for j in range (10, 110, 10)]
  
# printing points to be plotted on the x and y-axis
print("Points on x-axis are: ",X_axis)
print("Points on y-axis are: ",Y_axis)
  
# Creating a default plot
plt.figure(figsize=(8,6))
plt.plot(X_axis,Y_axis)
plt.scatter(X_axis,Y_axis)
plt.show()


Output:

Points on x-axis are:  [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

Points on y-axis are:  [25, 45, 65, 85, 105, 125, 145, 165, 185, 205]

default plot made using matplotlib including ticks

By viewing the above image, we can observe by default Matplotlib marks ticks on the x and y-axis.

Case 1.1: When we want to remove ticks on a single axis (here y-axis):

To remove the ticks on the y-axis, tick_params() method has an attribute named left and we can set its value to False and pass it as a parameter inside the tick_params() function. It removes the tick on the y-axis.

Python




# importing matplotlib library
import matplotlib.pyplot as plt
  
# making points to be plotted on x-axis and y-axis
X_axis = [i for i in range (10, 110, 10)]
Y_axis = [2*j+5 for j in range (10, 110, 10)]
  
# printing points to be plotted on the x and y-axis
print("Points on x-axis are: ", X_axis)
print("Points on y-axis are: ", Y_axis)
  
plt.figure(figsize = ( 8, 6))
plt.tick_params(left = False)
plt.plot(X_axis, Y_axis)
plt.scatter(X_axis, Y_axis)
plt.show()


Output:

plot made after using tick_params() method to remove ticks on y-axis

Case 1.2: When we want to remove ticks on a single axis (here x-axis):

To remove the ticks on the x-axis, tick_params() method accepts an attribute named bottom, and we can set its value to False and pass it as a parameter inside the tick_params() function. It removes the tick on the x-axis.

Python




# importing matplotlib library
import matplotlib.pyplot as plt
  
# making points to be plotted on x-axis and y-axis
X_axis = [i for i in range (10, 110, 10)]
Y_axis = [2*j+5 for j in range (10, 110, 10)]
  
# printing points to be plotted on the x and y-axis
print("Points on x-axis are: ", X_axis)
print("Points on y-axis are: ", Y_axis)
  
plt.figure(figsize = (8, 6))
plt.tick_params(bottom = False)
plt.plot(X_axis, Y_axis)
plt.scatter(X_axis, Y_axis)
plt.show()


Output:

plot made after using tick_params() method to remove ticks on x-axis

Case 2: Removing these ticks on both the axes using tick_params() method:

To remove the ticks on both the x-axis and y-axis simultaneously, we can pass both left and right attributes simultaneously setting its value to False and pass it as a parameter inside the tick_params() function. It removes the ticks on both x-axis and the y-axis simultaneously.

Python




# importing matplotlib library
import matplotlib.pyplot as plt
  
# making points to be plotted on x-axis and y-axis
X_axis = [i for i in range (10, 110, 10)]
Y_axis = [2*j+5 for j in range (10, 110, 10)]
  
# printing points to be plotted on the x and y-axis
print("Points on x-axis are: ", X_axis)
print("Points on y-axis are: ", Y_axis)
  
plt.figure(figsize = (8,6))
plt.tick_params(left = False, bottom = False)
plt.plot(X_axis, Y_axis)
plt.scatter(X_axis, Y_axis)
plt.show()


Output:

plot made after using tick_params() method to remove ticks on both x and y-axis

Case 3: When we want to remove both ticks and labels from both the axes

To remove both ticks and labels from both the axes simultaneously, apart from setting both left and right attributes to False, we will also use two additional attributes for labels which are- labelleft and labelbottom and we will set its value to False and pass it inside the tick_params() function. It will remove labels from both axes also.

Python3




# importing matplotlib library
import matplotlib.pyplot as plt
  
# making points to be plotted on x-axis and y-axis
X_axis = [i for i in range (10, 110, 10)]
Y_axis = [2*j+5 for j in range (10, 110, 10)]
  
# printing points to be plotted on the x and y-axis
print("Points on x-axis are: ", X_axis)
print("Points on y-axis are: ", Y_axis)
  
plt.figure(figsize = (8,6))
plt.tick_params(left = False, right = False , labelleft = False ,
                labelbottom = False, bottom = False)
  
plt.plot(X_axis, Y_axis)
plt.scatter(X_axis, Y_axis)
plt.show()


Output:

plot made after using tick_params() method to remove ticks  and labels on both x and y-axis



Similar Reads

How to Adjust Number of Ticks in Seaborn Plots?
In this article, we will discuss how to adjust the number of ticks in Seaborn Plots. Ticks are the values that are used to show some specific points on the X-Y coordinate, It can be a string or a number. We will see how we can choose an optimal or expand the number of ticks to display on both the x-axis and y-axis. The Axes.set_xticks() and Axes.se
2 min read
Python | Matplotlib.pyplot ticks
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2003.One of the greatest benefits of visualization is that it allows us visual access to huge
3 min read
Change the x or y ticks of a Matplotlib figure
Matplotlib is a plotting library in Python to visualize data, inspired by MATLAB, meaning that the terms used (Axis, Figure, Plots) will be similar to those used in MATLAB. Pyplot is a module within the Matplotlib library which is a shell-like interface to Matplotlib module. There are many ways to change the interval of ticks of axes of a plot of M
5 min read
How to Hide Axis Text Ticks or Tick Labels in Matplotlib?
The Matplotlib library by default shows the axis ticks and tick labels. Sometimes it is necessary to hide these axis ticks and tick labels. This article discusses some methods by which this can be done. Ticks: The axes' points are marked with ticks, which are also known as little geometrical scale lines.Tick labels: They are the name given to the t
4 min read
Matplotlib - Setting Ticks and Tick Labels
In this article, we are going to discuss how set Ticks and Tick labels in a graph. Ticks are the markers denoting data points on the axes and tick labels are the name given to ticks. By default matplotlib itself marks the data points on the axes but it has also provided us with setting their own axes having ticks and tick labels of their choice. Me
2 min read
How to Change the Number of Ticks in Matplotlib?
In this article, we will see how to change the number of ticks on the plots in matplotlib in Python. Method 1: Using xticks() and yticks() xticks() and yticks() is the function that lets us customize the x ticks and y ticks by giving the values as a list, and we can also give labels for the ticks, matters, and as **kwargs we can apply text effects
5 min read
Surface plots and Contour plots in Python
Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing the mplot3d toolkit. In this article, we will discuss the surface plots and contour
4 min read
Visualising ML DataSet Through Seaborn Plots and Matplotlib
Working on data can sometimes be a bit boring. Transforming a raw data into an understandable format is one of the most essential part of the whole process, then why to just stick around on numbers, when we can visualize our data into mind-blowing graphs which are up for grabs in python. This article will focus on exploring plots which could make y
7 min read
Place plots side by side in Matplotlib
Matplotlib is the most popular Python library for plotting graphs and visualizing our data. In Matplotlib we can create multiple plots by calling them once. To create multiple plots we use the subplot function of pyplot module in Matplotlib. Syntax: plt.subplot(nrows, .ncolumns, index) Parameters: nrows is for number of rows means if the row is 1 t
3 min read
Style Plots using Matplotlib
Matplotlib is the most popular package or library in Python which is used for data visualization. By using this library we can generate plots and figures, and can easily create raster and vector files without using any other GUIs. With matplotlib, we can style the plots like, an HTML webpage is styled by using CSS styles. We just need to import sty
3 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg