Sunday, November 17, 2024
Google search engine
HomeLanguagesMatplotlib.figure.Figure.get_tightbbox() in Python

Matplotlib.figure.Figure.get_tightbbox() 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 elements.

matplotlib.figure.Figure.get_tightbbox() method

The get_tightbbox() method figure module of matplotlib library is used to get the (tight) bounding box of the figure in inches.

Syntax: get_tightbbox(self, renderer, bbox_extra_artists=None)

Parameters: This method accepts the following parameters.

  • renderer : This parameter is the RendererBase instance
    renderer that will be used to draw the figures.
  • bbox_extra_artists : This parameter is the list of artists to include in the tight bounding box.

Returns: This method return BboxBase that contains the bounding box.

Below examples illustrate the matplotlib.figure.Figure.get_tightbbox() function in matplotlib.figure:

Example 1:




# Implementation of matplotlib function
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 = fig.get_tightbbox(fig.canvas.get_renderer(),
                      bbox_extra_artists = None)
   
print("Value Return by get_tightbbox():")
print(w)
    
fig.suptitle('matplotlib.figure.Figure.get_tightbbox()\
 function Example', fontweight ="bold"
  
plt.show()


Output:

Value Return by get_tightbbox():
TransformedBbox(
Bbox(x0=27.65277777777777, y0=29.077777777777776, x1=576.0, y1=422.4),
Affine2D(
[[0.01 0. 0. ]
[0. 0.01 0. ]
[0. 0. 1. ]]))

Example 2:




# Implementation of matplotlib function 
import numpy as np 
import matplotlib.pyplot as plt 
     
   
xx = np.random.rand(16, 30
      
fig, ax = plt.subplots() 
      
m = ax.pcolor(xx) 
m.set_zorder(-20
  
w = fig.get_tightbbox(fig.canvas.get_renderer(),
                      bbox_extra_artists = None)
   
print("Value Return by get_tightbbox():")
print(w)
    
  
fig.suptitle('matplotlib.figure.Figure.get_tightbbox()\
 function Example', fontweight ="bold"
  
plt.show()


Output:

Value Return by get_tightbbox():
TransformedBbox(
Bbox(x0=52.52777777777777, y0=29.077777777777776, x1=584.875, y1=427.9),
Affine2D(
[[0.01 0. 0. ]
[0. 0.01 0. ]
[0. 0. 1. ]]))

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments