Python如何画一张带有子图的图片

时间:2026-02-13 13:15:10

1、打开Python的shell界面,也就是idle界面。

Python如何画一张带有子图的图片

2、载入相关的工具包,这里用到了skimage和mathplot工具包:

from skimage import data

import matplotlib.pyplot as plt

Python如何画一张带有子图的图片

3、产生一组数据并且生成一个图片:

img=data.coffee() 

plt.figure(num='text',figsize=(8,8))

Python如何画一张带有子图的图片

4、画出各个子图,代码如下:

plt.subplot(2,2,1)

plt.imshow(img)

plt.subplot(2,2,2)

plt.imshow(img[:,:,0])

plt.subplot(2,2,3)

plt.imshow(img[:,:,1])

plt.subplot(2,2,4)

plt.imshow(img[:,:,2])

Python如何画一张带有子图的图片

5、采用以下指令显示我们的图片:

plt.show()

Python如何画一张带有子图的图片

6、查看显示结果如下图。

Python如何画一张带有子图的图片

© 2026 长短途
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com