![]() |
VOOZH | about |
Matplotlib library in python shows axis ticks and tick labels by default. Sometimes it is important to hide these axis ticks and tick labels. In this article we will discuss some methods by which this can be done. Before that lets have a understanding about each of them:
We are having different methods for this, some of them are explained below:
The xticks() and yticks() functions in Matplotlib are used to define the positions of the ticks on x and y axes respectively. These functions take a list of values that represent tick locations. By setting tick labels to an empty list we can hide ticks and their corresponding labels as shown below:
plt.xticks([])
plt.yticks([])
Output
In Matplotlib by default background color is white. By setting the color of the tick labels to white we can effectively hide them since they blend with the background. For this color attribute needs to pass with w (represents white) as a value to xticks() and yticks() function.
Output
A null Locator is a type of tick locator that makes axis ticks and tick labels disappear. Simply passing NullLocator() function will be enough.
np.random.rand(100): Creates an array with 100 random values where each value is a float between 0 and 1.Output
We can hide tick labels by passing a blank space (" ") as tick label. This will hide labels but keep ticks visible on the plot.
Output
set_visible(False)Using set_visibile() we can set visibility of tick labels as False, which will not make them appear in our plot. This method hides labels and ticks both.
Output
By using these methods we can easily customize our Matplotlib plots enhancing their clarity and focusing on the most important data points.