- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 show minor tick labels on a log-scale with Matplotlib?
To show minor tick labels on a log-scale with 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.
- Plot x and y data points using plot() method
- Get the current axis using gca() method.
- Set the yscale with log class by name.
- Change the appearance of ticks and tick label using ick_params() method.
- Set the minor axis formatter with format strings to format the tick.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 10) y = np.exp(x) plt.plot(x, y) ax = plt.gca() ax.set_yscale('log') plt.tick_params(axis='y', which='minor') ax.yaxis.set_minor_formatter(FormatStrFormatter("%.1f")) plt.show()
Output
- Related Articles
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to show tick labels on top of a matplotlib plot?
- Matplotlib log scale tick label number formatting
- Show tick labels when sharing an axis in Matplotlib
- How to rotate tick labels in a subplot in Matplotlib?
- How to disable the minor ticks of a log-plot in Matplotlib?
- Centering x-tick labels between tick marks in Matplotlib
- How to change the separation between tick labels and axis labels in Matplotlib?
- Fill the area under a curve in Matplotlib python on log scale
- How to plot contourf and log color scale in Matplotlib?
- How do I show logarithmically spaced grid lines at all ticks on a log-log plot using Matplotlib?
- What is the correct way to replace matplotlib tick labels with computed values?
- How to decrease the density of tick labels in subplots in Matplotlib?
- Getting empty tick labels before showing a plot in Matplotlib
- Change grid interval and specify tick labels in Matplotlib

Advertisements