欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python的matplotlib.pyplot显示图片

程序员文章站 2022-03-02 08:13:47
...

matplotlib.pyplot docs :https://matplotlib.org/api/pyplot_summary.html

用matplotlib库显示图片

'''
imread(*args, **kwargs)	Read an image from a file into an array.
imsave(*args, **kwargs)	Save an array as in image file.
imshow(X[, cmap, norm, aspect, …])	Display an image on the axes.
'''
import matplotlib.pyplot as plt  
  
img = plt.imread('G:\\picture\\2.jpg')  
plt.imshow(img)  
plt.show()  


matplotlib与PIL.Image结合显示

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from PIL import Image

img1=Image.open('G:\\picture\\1.jpg')
npimg1=np.array(img1)
plt.imshow(npimg1)
plt.show()