Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack.
Matplotlib.axis.Axis.get_tightbbox() Function
The Axis.get_tightbbox() function in axis module of matplotlib library is used to get the bounding box that encloses the axis.
Syntax: Axis.get_tightbbox(self, renderer)
Parameters: This method accepts the following parameters.
- renderer: This parameter is the RendererBase instance
rendererReturn value: This method returns the bounding box that encloses the axis.
Below examples illustrate the matplotlib.axis.Axis.get_tightbbox() function in matplotlib.axis:
Example 1:
Python3
# Implementation of matplotlib function from matplotlib.axis import Axis import matplotlib.pyplot as plt import numpy as np X = np.arange( - 10 , 10 , 0.5 ) Y = np.arange( - 10 , 10 , 0.5 ) U, V = np.meshgrid(X, Y) fig, ax = plt.subplots() ax.quiver(X, Y, U, V) ax.invert_xaxis() w = Axis.get_tightbbox(ax.xaxis, fig.canvas.get_renderer()) print ( "Value Return :\n" + str (w)) ax.grid() fig.suptitle( """matplotlib.axis.Axis.get_tightbbox() function Example\n""" , fontweight = "bold") plt.show() |
Output:
Value Return :
Bbox(x0=75.48368298368294, y0=29.077777777777776, x1=574.7670454545455, y1=43.077777777777776)
Example 2:
Python3
# Implementation of matplotlib function from matplotlib.axis import Axis import numpy as np import matplotlib.pyplot as plt xx = np.random.rand( 8 , 6 ) fig, ax = plt.subplots() m = ax.pcolor(xx) m.set_zorder( - 2 ) w = Axis.get_tightbbox(ax.xaxis, fig.canvas.get_renderer()) print ( "Value Return :\n" + str (w)) ax.grid() fig.suptitle( """matplotlib.axis.Axis.get_tightbbox() function Example\n""" , fontweight = "bold") plt.show() |
Output:
Value Return :
Bbox(x0=75.5625, y0=29.077777777777776, x1=580.4375, y1=43.077777777777776)