

- 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 to turn on minor ticks only on the y-axis Matplotlib?
First, we can create fig, ax using subplots() and then, we can plot the lines. After that, using ax.yaxis.set_minor_locator(tck.AutoMinorLocator()), we can turn on the minor ticks.
Steps
Create fig and ax variables using subplots method, where default nrows and ncols are 1.
Plot the line using two lists.
Set the locator of the minor ticker.
Dynamically find minor tick positions based on the positions of major ticks. The scale must be linear with major ticks evenly spaced.
Using plt.show() method, we can show the figure.
Example
import matplotlib.pyplot as plt import matplotlib.ticker as tck fig, ax = plt.subplots() plt.plot([0, 2, 4], [3, 6, 1]) ax.yaxis.set_minor_locator(tck.AutoMinorLocator()) plt.show()
Output
- Related Questions & Answers
- How to specify values on Y-axis in Python Matplotlib?
- How to disable the minor ticks of a log-plot in Matplotlib?
- How can I set the location of minor ticks in Matplotlib?
- How to force the Y axis to use only integers in Matplotlib?
- How to create minor ticks for a polar plot in matplotlib?
- How to set the ticks on a Fixed Position in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
- How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?
- Adding extra axis ticks using Matplotlib
- How to show minor tick labels on a log-scale with Matplotlib?
- How to move the Y-axis ticks from the left side of the plot to the right side in matplotlib?
- How to programmatically turn on Wifi on Android device?
- Pandas timeseries plot setting X-axis major and minor ticks and labels
- How to exponentially scale the Y axis with matplotlib?
Advertisements