In this Python tutorial, we will learn how to remove tick labels using matplotlib in python. And we will also cover the following topics:
- Matplotlib how to remove tick labels
- Matplotlib remove tick labels
- Matplotlib remove tick marks
- Matplotlib remove both tick labels and tick marks
- Matplotlib remove axis labels
- Matplotlib remove labels keep ticks
- Matplotlib remove ticks keep labels
- Matplotlib remove tick labels from subplot
- Matplotlib remove minor tick labels
- Matplotlib remove colorbar tick labels
- Matplotlib remove specific tick labels
Matplotlib how to remove tick labels
Before starting the topic, firstly understand what does tick and labels means.
- Ticks are the markers used to denote the points on the axes or we can say that the small geometrical scale lines.
- Tick labels are the name given to the ticks. Or we can say that tick labels are ticks that contain text called Text Ticks.
- Axis labels are the name given to the axes such as X-axis and Y-axis.
Sometimes programmers want to hide or remove the tick marks and tick labels. We have the feature of invisibility in matpolotlib by using which we make tick and labels invisible.
The following steps are used to remove matplotlib tick and labels which are outlined below:
- Defining Libraries: Import the important libraries which are required for the removal of the ticks and labels ( For visualization: pyplot from matplotlib, For data creation and manipulation: Numpy or Pandas).
- Define X and Y: Define the data values on X-axis and Y-axis. We can create an array or we can create a data frame for defining the values.
- Remove or Hide Ticks/Labels: By using yticks() and xticks() method we can easily remove the ticks and labels.
- Display: At last display the plot by using the show() method.
Read: How to install matplotlib python
Matplotlib remove tick labels
In this section, we study the removal of tick labels. Tick labels are the name given to the ticks in the plot.
There are different methods for hiding tick labels:
- By setting the color of the tick label white
- By setting the tick labels to be empty
- By setting the label argument to be empty
Matplotlib remove tick labels by setting color
If the background color of the plot is white. By setting the color of tick labels as white we can easily hide tick labels.
Basically, it does make the tick labels invisible but set the label color to be white. If the background color is not white, then this method doesn’t work.
Use xticks() and yticks() method and pass the color argument as ‘w’.
The syntax to remove tick labels by setting color as given below:
# X-axis tick label
matplotlib.pyplot.xticks(color='w')
# Y-axis tick label
matplotlib.pyplot.yticks(color='w')
The above-used parameter is defined below:
- color: specify a color to white.
Let’s understand the concept more clear with the help of an example:
# Import Library
import matplotlib.pyplot as plt
# Define Data
x = [1,2,3,4]
y = [6,12,18,24]
# Plot Graph
plt.plot(x,y)
plt.xlabel("X Label")
plt.ylabel("Y Label")
# xticks color white
plt.xticks(color='w')
# OR
# yticks color white
plt.yticks(color='w')
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library. After this, we define data points of the x-axis and y-axis.
- plt.plot() method is used for the creation of the graph.
- plt.xticks() method is used for removal of ticks labels at the x-axis. Here we pass the color parameter and set the color to be white.
- plt.yticks() method is used for removal of ticks labels at the y-axis. Here we pass the color parameter and set the color to be white.
- In last, we use show() method to display the graph.
Matplotlib remove tick labels by setting tick labels to be empty
By using xaxis.set_ticklabels([]) and yaxis.set_ticklabels([]) set the tick labels to be empty.
This method makes the tick labels invisible by setting the tick labels to be empty but leaves ticks visible.
The syntax for this is given below:
# For X-axis
matplotlib.axes.xaxis.set_ticklabels([])
# For Y-axis
matplotlib.axes.yaxis.set_ticklabels([])
Let’s see the example to understand the concept more clearly:
# Import Library
import matplotlib.pyplot as plt
# Define Data
x = [1,2,3,4]
y = [6,12,18,24]
# Plot Graph
plt.plot(x,y)
plt.xlabel("X Label")
plt.ylabel("Y Label")
ax = plt.gca()
# xticks setting to be empty
ax.axes.xaxis.set_ticklabels([])
# OR
# yticks setting to be empty
ax.axes.yaxis.set_ticklabels([])
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis.
- plt.plot() method is used for the creation of the graph.
- ax.axes.xaxis.set_ticklabels([]) method is used for the removal of ticks labels at the x-axis.
- ax.axes.yaxis.set_ticklabels([]) method is used for the removal of ticks labels at the y-axis.
- In last, we use show() method to display the graph.
Read Matplotlib set_xticklabels
Matplotlib remove tick labels by setting tick label argument to be empty
By using the plt.xticks() and plt.yticks() method and pass the argument label with empty.
The syntax for setting ticks labels to bet empty as below:
For x-asis
matplotlib.pyplot.xticks(x, label='')
For y-axis
matplotlib.pyplot.yticks(y, label='')
The above-used parameter is as follow:
- x: specifies the x-axis
- y: specifies the y-axis
- label: specifies the label. Which set to empty.
Let’s see the example for setting the label to be empty:
# Import Library
import matplotlib.pyplot as plt
# Define data
x = [1,2,3,4]
y = [8,9,10,11]
# plot graph
plt.plot(x, y, color='r', linewidth=5)
# set x label to be empty
plt.xticks(x, labels=" ")
# OR
# set y label to be empty
plt.yticks(y, labels=" ")
# display the graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis.
- plt.plot() method is used for the creation of the graph.
- plt.xticks() method is used for removal of ticks labels at the x-axis. Here we pass the argument labels and set them to be empty.
- plt.yticks() method is used for removal of ticks labels at the y-axis. Here we pass the argument labels and set them to be empty.
- In last, we use show() method to display the graph.
Read: Matplotlib plot a line
Matplotlib remove tick marks
By default when we plot a graph in matplotlib, we get ticks in our plot on both sides of the axes known as x-axis and y-axis.
But sometimes we don’t want to show the tick marks in our plot. So in that cases, we have to make these ticks invisible or we can say that we have to remove them.
By using the tick_params() method we can easily remove these ticks.
In the following cases we remove ticks:
- When we want to remove ticks on x-axis
- When we want to remove ticks on y-axis
- When we want to reomve ticks from both the axis
Matplotlib remove ticks on x-axis
Use tick_params() method to remove the on the x-axis. In this method pass the argument bottom and set its value False.
It removes the ticks only and leaves the tick labels as it is.
The syntax to remove the tick on the x-axis is as follow:
For x-axis
matplotlib.pyplot.tick_params(bottom=False)
Let’s understand this concept more clearly with the help of an example:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [8, 16, 20, 12]
# Remove ticks on x-axis
plt.tick_params(bottom = False)
# Plot Graph
plt.plot(x,y)
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis.
- plt.tick_params() method is used to reomve tick marks on x-axis.Here we pass the argument bottom and set it value False.
- plt.plot() method is used for the creation of the graph.
- In last, we use show() method to display the graph.
Matplotlib remove ticks on y-axis
Use tick_params() method to remove the on the y-axis. In this method pass, the argument left and set its value False.
It removes the ticks only and leaves the tick labels as it is.
The syntax to remove the tick on the y-axis is as follow:
For y-axis
matplotlib.pyplot.tick_params(left=False)
Let’s understand this concept more clearly with the help of an example:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [8, 16, 20, 12]
# Remove ticks on y-axis
plt.tick_params(left = False)
# Plot Graph
plt.plot(x,y)
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis.
- plt.tick_params() method is used to reomve tick marks on y-axis.Here we pass the argument left and set it value False.
- plt.plot() method is used for the creation of the graph.
- In last, we use show() method to display the graph.
Read Matplotlib set_yticklabels
Matplotlib remove ticks from both the axes
Use tick_params() method to remove the ticks on both axes. In this method pass, the argument bottom and left set its value False.
It removes the tick marks on both axes called as x-axis and y-axis.
The syntax to remove the tick on both the axes is as follow:
For both the axes
matplotlib.pyplot.tick_params(left=False,bottom=False)
Let’s understand this concept more clearly with the help of an example:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [8, 16, 20, 12]
# Remove ticks on x-axis and y-axis both
plt.tick_params(left = False, bottom = False)
# Plot Graph
plt.plot(x,y)
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis.
- plt.tick_params() method is used to remove tick marks on both the axis. Here we pass the argument left and bottom and set its value False.
- plt.plot() method is used for the creation of the graph.
- In last, we use the show() method to display the graph.
Read: Python plot multiple lines using Matplotlib
Matplotlib remove tick labels and tick marks
When we plot the graph in matplotlib the graph has both tick labels and tick marks. Sometimes, we need to remove both labels and marks.
There are the following methods to remove both ticks and labels as follow:
- By using set_visible() method
- By using set_ticks([]) method
- By using xticks([]) or yticks([]) method
- By using NullLocator() method
- By using tick_params() method
Matplotlib removes both labels and ticks by using xaxis.set_visible()
set_visible() method removes axis ticks, axis tick labels, and axis labels also. It makes the axis invisible completely.
Pass the argument False in this method to set the invisibility.
The syntax to remove both ticks and labels are as follow:
For x-axis
ax.axes.xaxis.set_visible(False)
For y-axis
ax.axes.yaxis.set_visible(False)
Let’s see the example to understand the concept:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [1, 2, 3, 6]
# Remove ticks and labels on x-axis and y-axis both
ax = plt.gca()
ax.axes.xaxis.set_visible(False)
ax.axes.yaxis.set_visible(False)
# Plot Graph
plt.plot(x,y)
# Display Graph
plt.show()
- In the above example, we use ax.axes.xaxis.set_visible() method to invisible both the ticks and labels on the x-axis and set the value False.
- ax.axes.yaxis.set_visible() method to invisible both the ticks and labels on the y-axis and set the value False.
- In last, we use the show() method to display the graph
Matplotlib removes both labels and ticks by using set_ticks([])
set_ticks([]) method removes axis ticks, axis tick labels. but it does not remove axis labels. Set the ticks empty and makes them invisible.
The syntax of set_ticks([]) is as follow:
For x-axis
ax.axes.xaxis.set_ticks([])
For y-axis
ax.axes.yaxis.set_ticks([])
Let’s understand the concept with the help of an example given below:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [1, 2, 3, 6]
# Remove ticks and labels on x-axis and y-axis both
ax = plt.gca()
ax.axes.xaxis.set_ticks([])
ax.axes.yaxis.set_ticks([])
# Plot Graph
plt.plot(x,y, color= 'red', linewidth=3)
# Display Graph
plt.show()
- In the above example, we use an ax.axes.xaxis.set_ticks() method to invisible both the ticks and labels on the x-axis and set the ticks empty.
- ax.axes.yaxis.set_ticks() method to invisible both the ticks and labels on the y-axis and set the ticks empty.
- In last, we use the show() method to display the graph.
Read Python Matplotlib tick_params + 29 examples
Matplotlib removes both labels and ticks by using xticks([]) and yticks([])
By using the method xticks() and yticks() you can disable the ticks and tick labels from both the x-axis and y-axis.
The syntax for disabling ticks and labels are as follow:
For x-axis
plt.xticks([])
For y-axis
plt.yticks([])
Let’s understand how we disable the ticks and labels with the help of an example:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [1, 2, 3, 6]
# Plot Graph
plt.plot(x,y, color= 'orange', linewidth=3)
# Remove ticks and labels on x-axis and y-axis both
plt.xticks([])
plt.yticks([])
# Display Graph
plt.show()
- In the above example, we use plt.xticks([]) method to invisible both the ticks and labels on the x-axis and set the ticks empty.
- plt.yticks() method to invisible both the ticks and labels on the y-axis and set the ticks empty.
- In last, we use the show() method to display the graph.
Matplotlib remove ticks and tick labels by using NullLocator()
To locate the ticks we use Null Locator. So by using NullLocator() method we hide both axis ticks and axis labels.
The syntax to remove ticks and tick labels are as follow:
# For x-axis
ax.xaxis.set_major_locator(ticker.NullLocator())
# For y-axis
ax.yaxis.set_major_locator(ticker.NullLocator())
Let’s see an example related to NullLocator() as follow:
# Import Libraries
import matplotlib.ticker as ticker
# Define data
x = [6, 8.3, 9, 2]
y = [1, 2, 3, 6]
# Define axes
ax = plt.axes()
# Plot Graph
ax.plot(x,y, color= 'cyan', linewidth=10)
# Remove ticks and labels on x-axis and y-axis
ax.xaxis.set_major_locator(ticker.NullLocator())
ax.yaxis.set_major_locator(ticker.NullLocator())
# Display Graph
plt.show()
- In the above example, firstly we have to import library matplotlib.ticker . After this, we have to define data in the form of X-axis and y-axis for plotting.
- plt.axes() method is used to define axes and ax.plt() method is used to plot the graph.
- Next, we have to use NullLocator() function as an argument in set_major_locator() method for both x-axis and y-axis.
- In the final, we call the show() method to display the graph.
Read Matplotlib multiple bar chart
Matplotlib remove ticks and labels by using tick_params()
To hide or remove both tick marks and tick labels from both axes (x-axis and y-axis) we have to use the tick_parmas() function.
Pass the following things as an argument ( left, bottom, labelleft, and labelbottom) and set their value to False to invisible the ticks and labels.
The syntax of the tick_params() method is as below:
matplotlib.pyplot.tick_params(left = False,labelleft = False ,
labelbottom = False, bottom = False)
Let’s see an example regarding this:
# Import Libraries
import matplotlib.pyplot as plt
# Define data
x = [5, 6, 7, 8]
y = [8, 16, 20, 12]
# Remove ticks and labels on x-axis and y-axis both
plt.tick_params(left = False, labelleft = False , labelbottom = False, bottom = False)
# Plot Graph
plt.plot(x,y)
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis.
- plt.tick_params() method is used to remove tick marks and tick labels on both the axis. Here we pass the argument left, bottom, labelleft, labelbottom, and set their values to be False.
- plt.plot() method is used for the creation of the graph.
- In last, we use the show() method to display the graph.
Read: What is matplotlib inline
Matplotlib remove axis labels
In matplotlib, the plot shows the ticks and tick labels by default. We also have the functionality to show axis labels on both sides of axes (x-axis and y-axis).
Firstly let’s understand what does axis labels mean:
- Basically axis labels tell us what does x-axis and y-axis represents.
- For example: The x-axis represents the number of students and the y-axis represents the marks of the students.
Now in this section, we study how to remove or hide the axis labels.
By using the set_visible() method we can hide the axis labels. It makes the complete axis invisible, include tick marks, tick labels, and also axis labels.
The syntax to remove axis labels:
For x-axis
ax.axes.xaxis.set_visible(False)
For y-axis
ax.axes.yaxis.set_visible(False)
Let’s see an example of a graph or plot having axis labels:
# Import Library
import matplotlib.pyplot as plt
# Define Data
student = [5, 10, 12, 16, 18]
marks= [99, 90, 80, 85, 75]
# Define axes label
plt.xlabel("No.Of students")
plt.ylabel("Marks of students")
# Plot Graph
plt.scatter(student,marks, color='r')
# Display Graph
plt.show()
- In the above example, firstly we import the matplotlib.pyplot library.
- After that, we define the data i.e. no. of students on the x-axis and marks of students on the y-axis.
- Next, we define the axis labels which tell us that x-axis represents the No.of students and the y-axis represents the marks of students. We use plt.xlabel() and plt.ylabel() method
- plt.scatter() method is used to plot the graph.
- Finally, we use the show() method to display what we have plotted.
Now let’s see with the help of an example how we remove axis labels:
# Import Library
import matplotlib.pyplot as plt
# Define Data
student = [5, 10, 12, 16, 18]
marks= [99, 90, 80, 85, 75]
# Define axes label
plt.xlabel("No.Of students")
plt.ylabel("Marks of students")
# Remove axis labels
ax = plt.gca()
ax.axes.xaxis.set_visible(False)
ax.axes.yaxis.set_visible(False)
# Plot Graph
plt.scatter(student,marks, color='r')
# Display Graph
plt.show()
- In the above example, we use an ax.axes.xaxis.set_visible() method and ax.axes.yaxis.set_visible() method and set their value False to invisible axis labels.
- This method also hides the axis ticks and tick labels.
Read: Matplotlib plot bar chart
Matplotlib remove labels keep ticks
The method that makes the tick labels hidden by setting the tick labels to be empty but leaves ticks visible.
We use xaxis.set_ticklabels([]) and yaxis.set_ticklabels([]) set the tick labels to be empty.
The syntax for this is given below:
# For X-axis
matplotlib.axes.xaxis.set_ticklabels([])
# For Y-axis
matplotlib.axes.yaxis.set_ticklabels([])
Let’s see the example to understand the concept more clearly:
# Import Library
import matplotlib.pyplot as plt
# Define Data
student = [5, 10, 12, 16, 18]
marks= [99, 90, 80, 85, 75]
# Plot Graph
plt.plot(student,marks)
plt.xlabel("No.Of students")
plt.ylabel("Marks of students")
ax = plt.gca()
# xticks setting to be empty
ax.axes.xaxis.set_ticklabels([])
# OR
# yticks setting to be empty
ax.axes.yaxis.set_ticklabels([])
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axis i.e. no.of students and marks of students.
- plt.plot() method is used for the creation of the graph.
- ax.axes.xaxis.set_ticklabels([]) method is used for the removal of ticks labels at the x-axis.
- ax.axes.yaxis.set_ticklabels([]) method is used for the removal of ticks labels at the y-axis.
- In last, we use show() method to display the graph.
Read: Matplotlib subplot tutorial
Matplotlib remove ticks keep labels
tick_params() method is used to remove the ticks on both axes.
In this method we pass, the argument bottom and left set its value False.
It removes the tick marks on both axes called as x-axis and y-axis.
The syntax to remove the ticks and keep labels is as follow:
For both the axes
matplotlib.pyplot.tick_params(left=False,bottom=False)
Let’s understand this concept more clearly with the help of an example:
# Import Library
import matplotlib.pyplot as plt
# Define Data
student = [5, 10, 12, 16, 18]
marks= [99, 90, 80, 85, 75]
# Define axes label
plt.xlabel("No.Of students")
plt.ylabel("Marks of students")
# Remove ticks keep labels
plt.tick_params(left = False, bottom = False)
# Plot Graph
plt.scatter(student,marks, color='r')
# Display Graph
plt.show()
- In the above example, we import matplotlib.pyplot library.
- After this, we define data points of the x-axis and y-axisi.e no. of .students and marsk of student.
- plt.tick_params() method is used to remove tick marks on both the axis. Here we pass the argument left and bottom and set its value False.
- plt.plot() method is used for the creation of the graph.
- In last, we use the show() method to display the graph.
Read: Matplotlib best fit line
Matplotlib remove tick labels from subplot
Here we will discuss how we can remove ticks and labels from the specific subplot.
We use the set_xticks() and set_yticks() functions to hide both the ticks and labels from the x-axis and y-axis respectively.
Here we have to set the ticks value to be empty.
Let’s understand the concept with the help of an example:
# Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
# Define Data
x1= [2, 6, 9, 5]
y1= [1, 3, 9, 15]
x2= [2, 6, 7, 9, 10]
y2= [3, 4, 6, 9, 12]
x3= [5, 8, 12]
y3= [3, 6, 9]
x4= [7, 8, 15]
y4= [6, 12, 18]
fig, ax = plt.subplots(2, 2)
# Remove tick labels
ax[0, 0].set_xticks([])
ax[0, 0].set_yticks([])
# Plot graph
ax[0, 0].plot(x1, y1)
ax[0, 1].plot(x2, y2)
ax[1, 0].plot(x3, y3)
ax[1, 1].plot(x4,y4)
# Display Graph
fig.tight_layout()
plt.show()
- In the above example, we plot multiple plots in a figure area. And we want to remove the ticks and labels of the specific plot.
- Here we use the set_xticks() and set_yticks() method to change the background of the plot.
- We use the set_xticks() and set_yticks() method with the first subplot and set tick value to be empty.
Read: Matplotlib subplots_adjust
Matplotlib remove minor tick labels
Minor ticks are the ticks between major ticks. Or we can say that minor ticks divide the major ticks into several parts.
By default, the minor tick labels are off.
In the section, we will study how to remove or turn off the minor ticks if the minor ticks are on.
The syntax to remove a minor tick:
matplotlib.pyplot.minorticks_off()
Let’s see the example of how to turn off the minor ticks:
Code#1(With minor tick)
By default log scales have minor ticks so we take this scale for understanding.
# Import Library
import numpy as np
import matplotlib.pyplot as plt
# Define Data
x = np.random.randint(-5, 5, 10)
y = np.exp(x)
# Plot Graph
plt.plot(y, x)
plt.xscale('log')
# Display Graph
plt.show()
In the above example, we plot a graph with a log scale so we understand how minor ticks look.
Code#2 (Without minor tick)
# Import Library
import numpy as np
import matplotlib.pyplot as plt
# Define Data
x = np.random.randint(-5, 5, 10)
y = np.exp(x)
# Plot Graph
plt.plot(y, x)
plt.xscale('log')
# Remove minor ticks
plt.minorticks_off()
# Display Graph
plt.show()
In the above example, now we use the minorticks_off() method to turn off the minor ticks.
Read: Matplotlib log log plot
Matplotlib remove colorbar tick labels
The Colorbar is the map of data values of colors. The colorbar() method is used to add a colorbar to the graph.
We can remove the following things from the color bar:
- Only ticks
- Both ticks and ticklabels
Let’s discuss each case one by one:
Matplotlib remove colobar only ticks
If we want to remove ticks from the colobar we have to set the size of the ticks to be 0.
The syntax for this is given below:
cbar.ax.tick_params(size=0)
The parameter used above is:
- size: The size of the tick marks in the color bar strip
Let’s take an example to understand how to remove ticks:
# Import libraries
import matplotlib.pyplot as plt
import numpy as np
# Plot image
a = np.random.random((5, 5))
plt.imshow(a, cmap='summer')
# Plot colorbar
cbar = plt.colorbar()
# Set ticklabels
labels = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
0.7, 0.8, 0.9, 1]
cbar.set_ticks(labels)
# Remove ticks
cbar.ax.tick_params(size=0)
# Plot graph
plt.show()
In the above example, we use the tick_params() method and pass the argument size, and set the value 0.
Read Matplotlib scatter plot legend
Matplotlib remove colobar both tick and ticklabels
If we want to remove both tick and ticklabels of the colorbar we have to use the function set_ticks([]) and pass the empty list.
The syntax for this is given below:
cbar.set_ticks([])
Let’s take an example to understand how to remove both tick and ticklabels
# Import libraries
import matplotlib.pyplot as plt
import numpy as np
# Plot image
a = np.random.random((5, 5))
plt.imshow(a, cmap='summer')
# Plot colorbar
cbar = plt.colorbar()
# Set ticklabels
labels = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
0.7, 0.8, 0.9, 1]
# Remove both ticks and ticklabels
cbar.set_ticks(labels)
# Plot graph
plt.show()
In the above example, we pass the empty list in the set_ticks() method.
Read: Matplotlib plot_date
Matplotlib remove specific tick labels
Here we are going to learn how we can hide some specific tick labels from the plot.
Use the method set_visible(False) with some specific ticks.
The syntax for this is:
xticks = ax.xaxis.get_major_ticks()
xticks[0].label1.set_visible(False)
# Here 0 is axis position which we want to hide
yticks = ax.yaxis.get_major_ticks()
yticks[4].label1.set_visible(False)
# Here 4 is axis position which we want to hide from y-axis
Let’s see the example for better understanding:
# Import Library
import matplotlib.pyplot as plt
# Define Data
student = [5, 10, 12, 16, 18]
marks= [99, 90, 80, 85, 75]
# Plot Graph
plt.plot(student,marks)
plt.xlabel("No.Of students")
plt.ylabel("Marks of students")
ax = plt.gca()
# remove specfic ticks
xticks = ax.xaxis.get_major_ticks()
xticks[0].label1.set_visible(False)
yticks = ax.yaxis.get_major_ticks()
yticks[4].label1.set_visible(False)
# Display Graph
plt.show()
- In the above example, we hide the specific ticks from both the x-axis and y-axis.
- Use the set_visible() method with the specific tick which you want to remove and the value to be False.
You may also like to read the following Matplotlib tutorials.
- Matplotlib dashed line
- Matplotlib scatter marker
- Matplotlib plot error bars
- Matplotlib change background color
- Matplotlib rotate tick labels
In this Python tutorial, we have discussed the “Matplotlib remove tick labels” and we have also covered some examples related to it. There are the following topics that we have discussed in this tutorial.
- Matplotlib how to remove tick labels
- Matplotlib remove tick labels
- Matplotlib remove tick marks
- Matplotlib remove both tick labels and tick marks
- Matplotlib remove axis labels
- Matplotlib remove labels keep ticks
- Matplotlib remove ticks keep labels
- Matplotlib remove tick labels from subplot
- Matplotlib remove minor tick labels
- Matplotlib remove colorbar tick labels
- Matplotlib remove specific tick labels
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.