Python中的 Matplotlib.figure.Figure.figimage()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 figure 模块提供了顶级 Artist,即 Figure,其中包含所有绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。
matplotlib.figure.Figure.figimage()函数
matplotlib 库的图形模块的 figimage() 方法用于向图形添加未重采样的图像。
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 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.
下面的示例说明了 matplotlib.figure 中的 matplotlib.figure.Figure.figimage()函数:
示例 1:
# 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()
输出:
示例 2:
# 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()
输出: