Open In App

Matplotlib.figure.Figure.figimage() 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.figimage() function

The figimage() method of figure module of matplotlib library is used to add a non-resampled image to the figure.

Syntax: figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None, vmin=None, vmax=None, origin=None, resize=False, **kwargs) 

Parameters: This accept the following parameters that are described below:

  • X: This parameter is the image data.
  • xo, yo: These parameters are the x/y image offset in pixels.
  • alpha : This parameter is the alpha blending value.
  • norm : This parameter is the Normalize instance to map the luminance to the interval [0, 1].
  • cmap : This parameter is the colormap to use.
  • vmin, vmax: These parameter are the data limits for the colormap.
  • origin : This parameter indicates where the [0, 0] index of the array is in the upper left or lower left corner of the axes.
  • resize : This parameter is used to resize the figure to match the given image size.

Returns: This method returns the matplotlib.image.FigureImage.

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

Example 1: 

Python3




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
 
fig = plt.figure()
nx = int(fig.get_figwidth() * fig.dpi)
ny = int(fig.get_figheight() * fig.dpi)
data = np.random.random((ny, nx))
fig.figimage(data)
 
fig.suptitle('matplotlib.figure.Figure.figimage()\
function Example', fontweight ="bold")
 
plt.show()


Output:

  

Example 2: 

Python3




# Implementation of matplotlib function
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
 
 
fig = plt.figure()
Z = np.arange(10000).reshape((100, 100))
Z[:, 50:] = 1
 
im1 = fig.figimage(Z, xo = 500, yo = 100,
                   origin ='lower')
 
im2 = fig.figimage(Z, xo = 100, yo = 100,
                   alpha =.6,
                   origin ='lower')
 
fig.suptitle('matplotlib.figure.Figure.figimage() \
function Example', fontweight ="bold")
 
plt.show()


Output:

 



Last Updated : 20 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads