Skip to content
Related Articles

Related Articles

Improve Article

Matplotlib.axis.Axis.get_tightbbox() function in Python

  • Last Updated : 08 Jun, 2020

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 
    renderer

Return 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)

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :