Matplotlib.pyplot.subplots_adjust() in Python (original) (raw)
Last Updated : 19 Apr, 2020
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, etc.
matplotlib.pyplot.subplots_adjust() Function
The subplots_adjust() function in pyplot module of matplotlib library is used to tune the subplot layout.
Syntax: matplotlib.pyplot.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)
Parameters: This method accept the following parameters that are described below:
- left : This parameter is the left side of the subplots of the figure.
- right : This parameter is the right side of the subplots of the figure.
- bottom : This parameter is the bottom of the subplots of the figure.
- top : This parameter is the top of the subplots of the figure.
- wspace : This parameter is the amount of width reserved for space between subplots expressed as a fraction of the average axis width.
- hspace : This parameter is the amount of height reserved for space between subplots expressed as a fraction of the average axis height.
Below examples illustrate the matplotlib.pyplot.subplots_adjust() function in matplotlib.pyplot:
Example 1:
import
matplotlib.pyplot as plt
x
=
[
1
,
12
,
3
,
9
]
y
=
[
1
,
4
,
9
,
16
]
labels
=
[
'Geeks1'
,
'Geeks2'
,
'Geeks3'
,
'Geeks4'
]
plt.plot(x, y)
plt.xticks(x, labels, rotation
=
'vertical'
)
plt.margins(
0.2
)
plt.subplots_adjust(bottom
=
0.15
)
plt.title(
'matplotlib.pyplot.subplots_adjust() Example'
)
plt.show()
Output:
Example 2:
import
numpy as np
import
matplotlib.pyplot as plt
from
matplotlib.widgets
import
TextBox
fig, ax
=
plt.subplots()
plt.subplots_adjust(bottom
=
0.2
)
t
=
np.arange(
-
2.0
,
2.0
,
0.001
)
s
=
np.sin(t)
+
np.cos(
2
*
t)
initial_text
=
"sin(t) + cos(2t)"
l,
=
plt.plot(t, s, lw
=
2
)
def
submit(text):
`` ydata
=
eval
(text)
`` l.set_ydata(ydata)
`` ax.set_ylim(np.
min
(ydata), np.
max
(ydata))
`` plt.draw()
axbox
=
plt.axes([
0.4
,
0.05
,
0.3
,
0.075
])
text_box
=
TextBox(axbox,
'Formula Used : '
,
`` initial
=
initial_text)
text_box.on_submit(submit)
fig.suptitle(
'matplotlib.pyplot.subplots_adjust() Example'
)
plt.show()
Output:
Similar Reads
- Matplotlib.pyplot.subplot() function in Python Prerequisites: matplotlib subplot() function adds subplot to a current figure at the specified grid position. Â It is similar to the subplots() function however unlike subplots() it adds one subplot at a time. So to create multiple plots you will need several lines of code with the subplot() function 2 min read
- Matplotlib.pyplot.subplot_tool() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8]) plt.show( 1 min read
- Matplotlib.pyplot.subplot2grid() in python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.pyplot.subplot2grid() The Matplotlib.pyplot.subplot2grid() function give addi 3 min read
- Matplotlib.pyplot.autumn() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read
- Matplotlib.axes.SubplotBase() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read
- Matplotlib.pyplot.axis() in Python Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Pyplot is a Matplotlib module which provides a MATLAB-like interface. Matplotlib is designed to be as usable as MATLAB, with the ability to use Python and the advantage of being free and open-so 1 min read
- Matplotlib.pyplot.suptitle() function in Python Matplotlib is a library in Python and it is a mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.suptitle() Function The suptitle() function in pyplot module of the matplotlib library is used to 3 min read
- Matplotlib.pyplot.axes() in Python Pyplot is another module of matplotlib that enables users to integrate MATLAB within Python environment, and thus providing MATLAB like interface and making Python visually interactive. Matplotlib.pyplot.axes() pyplot.axes is a function of the matplotlib library that adds axes to the current graph a 2 min read
- Matplotlib.pyplot.show() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. Sample Code - # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8]) plt.sho 2 min read
- Python Plotly - Subplots and Inset Plots Perquisites: Python Plotly One of the most deceptively-powerful features of Plotly data visualization is the ability for a viewer to quickly analyze a sufficient amount of information about data when pointing the cursor over the point label appears. In this article, we are going to see about the Su 3 min read