

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I set the location of minor ticks in Matplotlib?
To set the location of the minor ticks in Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points using numpy.
- Create a figure and a set of subplots.
- Plot x and y data points using plot() method.
- To locate minor ticks, use set_minor_locator() method.
- To show the minor ticks, use grid(which='minor').
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import AutoMinorLocator plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 100) y = np.log(x) fig, ax = plt.subplots() ax.plot(x, y) minor_locator = AutoMinorLocator(2) ax.xaxis.set_minor_locator(minor_locator) plt.grid(which='minor') plt.show()
Output
- Related Questions & Answers
- How to disable the minor ticks of a log-plot in Matplotlib?
- How to create minor ticks for a polar plot in matplotlib?
- How to turn on minor ticks only on the y-axis Matplotlib?
- How can I change the font size of ticks of axes object in Matplotlib?
- How to set the number of ticks in plt.colorbar in Matplotlib?
- How to set the ticks on a Fixed Position in Matplotlib?
- How to set axis ticks in multiples of pi in Python Matplotlib?
- How can I set the 'backend' in matplotlib in Python?
- How to add Matplotlib Colorbar Ticks?
- How to change the color of the ticks in the colorbar in Matplotlib?
- How to change the spacing between ticks in Matplotlib?
- How do I change the font size of ticks of matplotlib.pyplot.colorbar.ColorbarBase?
- How can I get the color of the last figure in Matplotlib?
- How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
- How can I hide the axes in Matplotlib 3D?
Advertisements