2
我需要一些帮助与蟒蛇的情节。多图片背景matplotlib
我takling从文档的例子,为了剧情是这样的:
但现在我的问题是,如果这样做有可能使情节与这种风格(正方形)但在每个方格上显示不同的图像。
我想要显示的图像将从计算机中加载。
所以,要尽可能清楚:我想在正方形0,0上显示图像,在正方形0,1上显示不同的图像,等等。
我需要一些帮助与蟒蛇的情节。多图片背景matplotlib
我takling从文档的例子,为了剧情是这样的:
但现在我的问题是,如果这样做有可能使情节与这种风格(正方形)但在每个方格上显示不同的图像。
我想要显示的图像将从计算机中加载。
所以,要尽可能清楚:我想在正方形0,0上显示图像,在正方形0,1上显示不同的图像,等等。
的一种方法是将图像阵列打包成一个大的数组,然后在大阵列上呼吁imshow
:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import matplotlib.image as mimage
import scipy.misc as misc
import itertools as IT
height, width = 400, 400
nrows, ncols = 2, 4
# load some arrays into arrs
filenames = ['grace_hopper.png', 'ada.png', 'logo2.png']
arrs = list()
for filename in filenames:
datafile = cbook.get_sample_data(filename, asfileobj=False)
arr = misc.imresize(mimage.imread(datafile), (height, width))[..., :3]
arrs.append(arr)
arrs = IT.islice(IT.cycle(arrs), nrows*ncols)
# make a big array
result = np.empty((nrows*height, ncols*width, 3), dtype='uint8')
for (i, j), arr in IT.izip(IT.product(range(nrows), range(ncols)), arrs):
result[i*height:(i+1)*height, j*width:(j+1)*width] = arr
fig, ax = plt.subplots()
ax.imshow(result)
plt.show()
看起来不错,感谢您的帮助 – codeKiller 2014-10-08 06:37:49