2013-07-26 3 views
2

일부 폴더에 이미지가 i-1 인 경우를 가정 해 봅니다. 나는 (이 이미지의 사각형을 만들 것 같은)이 코드는 열 int((i-1)**0.5)의 수와 일부 그리드matplotlib을 사용하여 .png의 잘못된 점을 그릴 방법

import matplotlib.pyplot as plt 
import matplotlib.image as mplimg 
import pylab 
import numpy as np 

for j in range(i): 
    image=mplimg.imread("c:\\users\\laurence\\dropbox\\ggl\\images\\"+str(j)+".png") 
    arr=np.asarray(image) 

답변

4

안된를 렌더링 할 수 있도록 있지만 일반적인 방법은 어떻게. 이 응답에 대한

import matplotlib.pyplot as plt 
import glob 
import numpy as np 

# glob won't preserve the order that the files are in (if you need that, you can 
# simply do what you were already doing. Globbing is simpler, though. 
filenames = glob.glob('c:/path/to/your/photos/*.png') 
# Forward slashes work for pathnames on windows, too (at least in python) 

# Let's not assume that there's an exact square number of images 
nrows = np.ceil(np.sqrt(len(filenames))).astype(int) 
ncols = len(filenames) // nrows 

# Subplots returns a figure and a _2d array_ of axes in a grid. 
fig, axes = plt.subplots(nrows, ncols) 

# Note that we're iterating over ``axes.flat``, not just axes (which is 2d) 
for filename, ax in zip(filenames, axes.flat): 
    data = plt.imread(filename) 
    ax.imshow(data) 

    # You might want to hide the labels, border, etc 
    ax.axis('off') 

# Not necessary, but this will give you more evenly located subplots 
fig.tight_layout() 
plt.show() 
+0

많은 감사하지만 나는이 내가받을 때 : AttributeError를 '모듈'개체가 내 인생에 어떤 속성 'suplots' – Freeman

+0

오타가 있습니다. '서브 플로트'여야합니다. –

+0

아, 그냥 테스트하고 독서 감사합니다. – Freeman

관련 문제