matplotlib.pyplot.minorticks_off() in Python

matplotlib.pyplot.minorticks_off() in Python

The minorticks_off() function in matplotlib.pyplot is used to remove minor ticks from the current plot. In matplotlib, each axis (be it x, y, or even z in three-dimensional plots) can have two sets of ticks: major and minor. Major ticks are usually the primary division you see on an axis, while minor ticks subdivide those major divisions further.

Using minorticks_off(), you can quickly turn off the display of minor ticks without affecting the major ticks.

Here's an example to demonstrate:

import matplotlib.pyplot as plt import numpy as np # Create a simple plot x = np.linspace(0, 10, 100) y = np.sin(x) fig, ax = plt.subplots() ax.plot(x, y) # Turn on minor ticks ax.minorticks_on() # Plot will display with minor ticks plt.show() # Now, turn off minor ticks and display the plot again plt.figure() plt.plot(x, y) plt.minorticks_off() plt.show() 

In the example above:

  1. A sine curve is plotted.
  2. Minor ticks are explicitly turned on using ax.minorticks_on().
  3. After showing the plot with minor ticks, another plot is displayed where the minor ticks have been turned off using plt.minorticks_off().

This function provides a quick way to control the visibility of minor ticks when customizing your plots in matplotlib.


More Tags

count-unique diacritics animated-webp prcomp tinymce controlvalueaccessor intentservice rspec-rails gulp docker-compose

More Programming Guides

Other Guides

More Programming Examples