- 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 change the separation between tick labels and axis labels in Matplotlib?
To change the separation between tick labels and axis labels in Matplotlib, we can use labelpad in xlabel() method.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Plot data points of a list using plot() method.
- Set the ticks on the axes.
- Set X and Y axes margins to 0.
- Set the X-axis label with labelpad.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([1, 2, 3, 4, 5]) plt.xticks([1, 2, 3, 4, 5]) plt.margins(x=0, y=0) plt.xlabel("X-axis", labelpad=7) plt.show()
Output
- Related Articles
- Change grid interval and specify tick labels in Matplotlib
- Hide axis values but keep axis tick labels in matplotlib
- Show tick labels when sharing an axis in Matplotlib
- Centering x-tick labels between tick marks in Matplotlib
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to rotate tick labels in a subplot in Matplotlib?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to rotate X-axis tick labels in Pandas bar plot?
- How to decrease the density of tick labels in subplots in Matplotlib?
- How to increase/reduce the fontsize of X and Y tick labels in Matplotlib?
- How to create a plot with tick marks between X-axis labels in base R?
- How to show tick labels on top of a matplotlib plot?
- How to hide the Y-axis tick labels on a chart in Python Plotly?
- How to show minor tick labels on a log-scale with Matplotlib?
- Increasing the space for X-axis labels in Matplotlib

Advertisements