본문 바로가기

카테고리 없음

matplotlib , pyplot , draw mutile images as N x N square

# Let draw images as size 5 x 5 usgin matplotlib , pyplot 

# result will be like this



# Assume you have images to display in 'images'

images = x_train[samples]   # 25 images in this example



# plot the 25 mnist digit images as 5x5

import matplotlib.pyplot as plt

import numpy as np


plt.figure(figsize=(10,10)) # image size

for i in range(len(samples)):

    plt.subplot(5, 5, i + 1) # 5 x 5 format , (i+1)-th position

    image = images[i]

    plt.imshow(image, cmap='gray')

    plt.axis('off')

#     plt.axis('on')


# plt.savefig("mnist-samples.png") # if you want save as image file

plt.show()

plt.close('all')