在matplotlib子图中绘制几个图像文件 [英] plot several image files in matplotlib subplots
本文介绍了在matplotlib子图中绘制几个图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个矩阵子图并在另一个子图中从目录显示每个BMP文件,但是我找不到适合我问题的合适解决方案,有人可以帮我吗?
I would like to create a matrix subplot and display each BMP files, from a directory, in a different subplot, but I cannot find the appropriate solution for my problem, could somebody helping me?.
这是我拥有的代码:
import os, sys
from PIL import Image
import matplotlib.pyplot as plt
from glob import glob
bmps = glob('*trace*.bmp')
fig, axes = plt.subplots(3, 3)
for arch in bmps:
i = Image.open(arch)
iar = np.array(i)
for i in range(3):
for j in range(3):
axes[i, j].plot(iar)
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
执行后出现以下错误:
推荐答案
native matplotlib仅支持PNG图像,请参见 http://matplotlib.org/users/image_tutorial.html
natively matplotlib only supports PNG images, see http://matplotlib.org/users/image_tutorial.html
然后总是读取图像-绘制图像
读取图像
img1 = mpimg.imread('stinkbug1.png')
img2 = mpimg.imread('stinkbug2.png')
绘图图像(2个子图)
plt.figure(1)
plt.subplot(211)
plt.imshow(img1)
plt.subplot(212)
plt.imshow(img2)
plt.show()
按照 http://matplotlib.org/users/image_tutorial.html (因为有导入库)
here is a thread on plotting bmps with matplotlib: Why bmp image displayed as wrong color with plt.imshow of matplotlib on IPython-notebook?
这篇关于在matplotlib子图中绘制几个图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文