Open In App

Matplotlib.figure.Figure.get_window_extent() in Python

Improve
Improve
Like Article
Like
Save
Share
Report

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:




# 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()


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:




# 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()


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.]]))


Last Updated : 30 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads