Skip to content
Related Articles

Related Articles

Matplotlib.figure.Figure.get_window_extent() in Python
  • Last Updated : 30 Apr, 2020

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_window_extent() method

The get_window_extent() method figure module of matplotlib library is used to get the figure bounding box in display space.

Syntax: get_window_extent(self, *args, **kwargs)

Parameters: This method does not accepts any parameter.

Returns: This method return the figure bounding box in display space.



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

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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_window_extent()
   
print("Value Return by get_window_extent():")
print(w)
    
fig.suptitle('matplotlib.figure.Figure.get_window_extent()\
 function Example', fontweight ="bold"
  
plt.show()

chevron_right


Output:

Value Return by get_window_extent():
TransformedBbox(
    Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8),
    Affine2D(
        [[100.   0.   0.]
         [  0. 100.   0.]
         [  0.   0.   1.]]))

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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_window_extent()
   
print("Value Return by get_window_extent():")
print(w)
    
fig.suptitle('matplotlib.figure.Figure.get_window_extent()\
 function Example', fontweight ="bold"
  
plt.show()

chevron_right


Output:

Value Return by get_window_extent():
TransformedBbox(
    Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8),
    Affine2D(
        [[100.   0.   0.]
         [  0. 100.   0.]
         [  0.   0.   1.]]))

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :