Python中的 Matplotlib.pyplot.figimage()函数
Matplotlib是Python中广泛使用的库,用于绘制各种图形,因为它还为复杂的绘图提供了非常有效的方法和易于理解的方法。 pyplot 是使 matplotlib 像 MATLAB 一样工作的命令样式函数的集合。
figimage()函数
matplotlib.pyplot.figimage()是一种将非重采样图像添加到图形的方法。通常,它根据原点将图像附加到左下角或左上角。
Syntax: matplotlib.pyplot.figimage(*args, **kwargs)
Parameters:
alpha is a float valued parameter, It is used to give the blending value for the image. It is an optional parameter. When not specified, it takes the default value as ‘None’.
Xo, Yo is another important parameter which states the shape of the image data. Usually it can be ‘both’, ‘x’, or ‘y’. It takes the x/y image offset in pixels.
**kwargs It is an additional parameter generally known as kwargs. They are Artist kwargs passed on to FigureImage.
现在让我们通过一个简单的例子来说明 matplotlib.pyplot.figimage() 的工作原理。
示例 1:
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 = 50, yo = 0,
origin ='lower')
im2 = fig.figimage(Z, xo = 100, yo = 100,
alpha =.8, origin ='lower')
plt.show()
输出:
示例 2:
import numpy as np
import matplotlib.pyplot as plt
im = np.zeros((40, 40, 3), dtype = np.float)
fig, ax = plt.subplots()
im = fig.figimage(im, 100, 60)
ax.scatter([0, 1, 2, 3, 4], [0, 1, 2, 3, 4])
ax.set_zorder(1)
im.set_zorder(0)
ax.patch.set_visible(False)
plt.show()
输出: