How to decrease the density of tick labels in subplots in Matplotlib?


To decrease the density of tick labels in subplots in matplotlib, we can assign the minimum value to density.

Steps

  • Initialize a variable, density.

  • Create x and y data points using numpy.

  • Plot x and y data points using plot() method.

  • Get or set the current tick locations and labels of the X-axis using xticks() method.

  • To display the figure, use show() method.

Example

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
density = 10
x = np.linspace(-2, 2, density)
y = np.sin(x)
plt.plot(x, y)
plt.xticks(x)
plt.show()

Output

Updated on: 12-May-2021

692 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements