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

python matplotlib.pyplot 显示图像

程序员文章站 2022-05-27 16:01:48
...

1. example1

import cv2
import matplotlib.pyplot as plt

img1 = cv2.imread('/media/data_2/everyday/0930/1.jpeg')
img2 = cv2.imread('/media/data_2/everyday/0930/2.jpg')
img3 = cv2.imread('/media/data_2/everyday/0930/3.jpeg')
img4 = cv2.imread('/media/data_2/everyday/0930/4.jpeg')

img1 = cv2.resize(img1,(800,800))
img2 = cv2.resize(img2,(800,800))
img3 = cv2.resize(img3,(800,800))
img4 = cv2.resize(img4,(800,800))

# img[:, :, ::-1]是将BGR转化为RGB
plt.subplot(141) #要生成1行4列,这是第一个图plt.subplot('行','列','编号')
plt.imshow(img1[:, :, ::-1])  
plt.title('dog-1')
plt.subplot(142)
plt.imshow(img2[:, :, ::-1]) 
plt.title('dog-2')

plt.subplot(143)
plt.imshow(img3[:, :, ::-1])
plt.title('dog-3') 
plt.subplot(144)
plt.imshow(img4[:, :, ::-1]) 
plt.title('cat-1')
plt.show()

python matplotlib.pyplot 显示图像

2. example2

import cv2
import matplotlib.pyplot as plt

img1 = cv2.imread('/media/data_2/everyday/0930/1.jpeg')
img2 = cv2.imread('/media/data_2/everyday/0930/2.jpg')
img3 = cv2.imread('/media/data_2/everyday/0930/3.jpeg')
img4 = cv2.imread('/media/data_2/everyday/0930/4.jpeg')

img1 = cv2.resize(img1,(800,800))
img2 = cv2.resize(img2,(800,800))
img3 = cv2.resize(img3,(800,800))
img4 = cv2.resize(img4,(800,800))

# img[:, :, ::-1]是将BGR转化为RGB
plt.subplot(121) #要生成1行2列,这是第一个图plt.subplot('行','列','编号')
plt.imshow(img1[:, :, ::-1])  
plt.title('dog-1')
plt.subplot(122)
plt.imshow(img2[:, :, ::-1]) 
plt.title('dog-2')

fig = plt.figure()
plt.subplot(121)
plt.imshow(img3[:, :, ::-1])
plt.title('dog-3') 
plt.subplot(122)
plt.imshow(img4[:, :, ::-1]) 
plt.title('cat-1')
plt.show()

python matplotlib.pyplot 显示图像

3. example3

import cv2
import numpy as np
import matplotlib.pyplot as plt
t=np.arange(0.0,2.0,0.1)
s=np.sin(t*np.pi)
plt.subplot(2,2,1) #要生成两行两列,这是第一个图plt.subplot('行','列','编号')
plt.plot(t,s,'b--')
plt.ylabel('y1')
plt.subplot(2,2,2) #两行两列,这是第二个图
plt.plot(2*t,s,'r--')
plt.ylabel('y2')
plt.subplot(2,2,3)#两行两列,这是第三个图
plt.plot(3*t,s,'m--')
plt.subplot(2,2,4)#两行两列,这是第四个图
plt.plot(4*t,s,'k--')
plt.show()

python matplotlib.pyplot 显示图像