plt画图

plt显示图片:

import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1, 2, figsize = (20, 10))
ax1.imshow(x, cmap='gray') #0-255级灰度,0为黑色,1为白色
ax1.set_title('images')
ax2.imshow(y, cmap='gray_r') #翻转gray的显示,黑白颠倒
ax2.set_title('masks')

【注意】这个gray_r只对本身是灰度图像才比较明显,如果本身是彩色图像,即使黑白颠倒了也没有太大差别。

x和y是灰度图像:

x和y是彩色图像:

plt画曲线图

import matplotlib.pyplot as plt
x = np.arange(20)
y1 = x
y2 = x**2
y3 = x+2
fig, (ax1, ax2) = plt.subplots(1, 2, figsize = (20, 10))
_ = ax1.plot(x,y1,'b-',x,y2,'r-')
ax1.legend(['x','x**2'])
_ = ax2.plot(x,y3,'b-')
ax2.legend('x+2')
plt.title('func')
plt.show()

猜你喜欢

转载自blog.csdn.net/aaon22357/article/details/83380192
plt