📜  Python中的 matplotlib.pyplot.imread()

📅  最后修改于: 2022-05-13 01:55:02.134000             🧑  作者: Mango

Python中的 matplotlib.pyplot.imread()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 PyplotMatplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。

matplotlib.pyplot.imread()函数:

matplotlib 库的 pyplot 模块中的imread()函数用于将图像从文件读取到数组中。

下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.imread()函数:

示例 #1:

# Implementation of matplotlib function
import numpy as np
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt
  
with cbook.get_sample_data('loggf.png') as image_file:
    image = plt.imread(image_file)
  
fig, ax = plt.subplots()
ax.imshow(image)
ax.axis('off')
  
plt.title('matplotlib.pyplot.imread() function Example', 
                                     fontweight ="bold")
plt.show()

输出:

示例 #2:

# Implementation of matplotlib function
import numpy as np
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt
  
  
with cbook.get_sample_data('loggf.png') as file:
    im = image.imread(file)
  
fig, ax = plt.subplots()
  
ax.plot(np.cos(10 * np.linspace(0, 1)), '-o', ms = 15,
                            alpha = 0.6, mfc ='green')
  
ax.grid()
fig.figimage(im, 10, 10, zorder = 3, alpha =.5)
  
plt.title('matplotlib.pyplot.imread() function Example', 
                                     fontweight ="bold")
plt.show()

输出: