2014-10-07 65 views
2

我需要一些幫助與蟒蛇的情節。多圖片背景matplotlib

我takling從文檔的例子,爲了劇情是這樣的:

enter image description here

但現在我的問題是,如果這樣做有可能使情節與這種風格(正方形)但在每個方格上顯示不同的圖像。

我想要顯示的圖像將從計算機中加載。

所以,要儘可能清楚:我想在正方形0,0上顯示圖像,在正方形0,1上顯示不同的圖像,等等。

回答

2

的一種方法是將圖像陣列打包成一個大的數組,然後在大陣列上呼籲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() 

enter image description here

+0

看起來不錯,感謝您的幫助 – codeKiller 2014-10-08 06:37:49