- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Adjusting the spacing between the edge of the plot and the X-axis in Matplotlib
To adjust the spacing between the edge of the plot and the X-axis, we can use tight_layout() method or set the bottom padding of the current figure.
- 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.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 100) y = np.exp(x) plt.plot(x, y, c='red', lw=1) plt.show()
Output
- Related Articles
- Show the origin axis (x,y) in Matplotlib plot
- How to change the range of the X-axis and Y-axis in Matplotlib?
- Matplotlib – How to plot the FFT of signal with correct frequencies on the X-axis?
- Setting the spacing between grouped bar plots in Matplotlib
- How to change the spacing between ticks in Matplotlib?
- Filling the region between a curve and X-axis in Python using Matplotlib
- How to plot data against specific dates on the X-axis using Matplotlib?
- Increase the distance between the title and the plot in Matplotlib
- How to plot the X-axis labels on the upper-side of the plot in R?
- Adjusting the heights of individual subplots in Matplotlib in Python
- Moving X-axis in Matplotlib during real-time plot
- How to increase the spacing between subplots in Matplotlib with subplot2grid?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to customize the X-axis in Matplotlib?
- Show decimal places and scientific notation on the axis of a Matplotlib plot

Advertisements