Matplotlib.figure.Figure.set_constrained_layout() in Python Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements. matplotlib.figure.Figure.set_constrained_layout() method The set_constrained_layout() method figure module of matplotlib library is used to set whether constrained_layout is used upon drawing. Syntax: set_constrained_layout(self, constrained) Parameters: This method accept the following parameters that are discussed below: constrained: This parameter is the bool or dict or None. Returns: This method returns the axes. Below examples illustrate the matplotlib.figure.Figure.set_constrained_layout() function in matplotlib.figure: Example 1: Python3 1== # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots(constrained_layout = True) x = np.arange(0.02, 1, 0.02) np.random.seed(19680801) y = np.random.randn(len(x)) ** 2 ax.loglog(x, y) ax.set_xlabel('f [Hz]') ax.set_ylabel('PSD') ax.set_title('Random spectrum') def forward(x): return 1 / x def inverse(x): return 1 / x fig.set_constrained_layout(True) fig.suptitle("""matplotlib.figure.Figure.set_constrained_layout() function Example\n\n""", fontweight ="bold") plt.show() Output: Example 2: Python3 1== # Implementation of matplotlib function import matplotlib import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec fig = plt.figure() gs = fig.add_gridspec(3, 3) ax = fig.add_subplot(gs[0, :]) ax.set_title('gs[0, :]') ax2 = fig.add_subplot(gs[1, :-1]) ax2.set_title('gs[1, :-1]') fig.set_constrained_layout(False) fig.suptitle("""matplotlib.figure.Figure.set_constrained_layout() function Example\n\n""", fontweight ="bold") plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.figure.Figure.set_constrained_layout_pads() in Python S SHUBHAMSINGH10 Follow Improve Article Tags : Python Python-matplotlib Matplotlib figure-class Practice Tags : python Similar Reads Matplotlib.figure.Figure.set_constrained_layout_pads() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot 2 min read Matplotlib.figure.Figure.get_constrained_layout() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot 2 min read Matplotlib.figure.Figure.get_constrained_layout_pads() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot 2 min read Matplotlib.figure.Figure.set_tight_layout() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot 2 min read Matplotlib.figure.Figure.tight_layout() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot 2 min read Matplotlib.figure.Figure.set_canvas() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot 2 min read Like