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.init_layoutbox() method
The init_layoutbox() method figure module of matplotlib library is used to initialize the layoutbox for use in constrained_layout.
Syntax: init_layoutbox(self)
Parameters: This method does not accept any parameters.
Returns: This method does not returns any value.
Below examples illustrate the matplotlib.figure.Figure.init_layoutbox() function in matplotlib.figure:
Example 1:
# Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np import matplotlib.gridspec as gridspec fig = plt.figure() gs = gridspec.GridSpec( 2 , 2 ) for i in range ( 2 ): ax = fig.add_subplot(gs[ 1 , i]) ax.set_ylabel( 'Y label' ) ax.set_xlabel( 'X label' ) if i = = 0 : for tick in ax.get_xticklabels(): tick.set_rotation( 45 ) fig.init_layoutbox() fig.suptitle( """matplotlib.figure.Figure.init_layoutbox() function Example\n\n""" , fontweight = "bold") plt.show() |
Output:
Example 2:
# Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt fig = plt.figure() fig.subplots_adjust(top = 0.8 ) ax1 = fig.add_subplot( 211 ) t = np.arange( 0.0 , 1.0 , 0.01 ) s = np.sin( 2 * np.pi * t) line, = ax1.plot(t, s, color = 'green' , lw = 2 ) np.random.seed( 19680801 ) ax2 = fig.add_axes([ 0.15 , 0.1 , 0.7 , 0.3 ]) n, bins, patches = ax2.hist(np.random.randn( 1000 ), 50 , facecolor = 'yellow' , edgecolor = 'yellow' ) fig.init_layoutbox() fig.suptitle( """matplotlib.figure.Figure.init_layoutbox() function Example\n\n""" , fontweight = "bold") plt.show() |
Output: