# -*- coding: utf-8 -*-
#
# google colab を使う場合は，下の2行をコメントアウトし．ファイルをアップロード
# from google.colab import files
# f= files.upload()

import numpy as np
import matplotlib.pyplot as plt
import scipy.io

# 手書き数字のデータをロードし、変数digitsに格納
data = scipy.io.loadmat("digit.mat")

x = data["X"]
# x.shape # (256, 500, 10)
[d, n, nc] = x.shape

X3 = x[:,:,2].T  # 手書き数字3の500例．X3は 500x256 行列

fig = plt.figure()

nx=15
ny=10
# 手書き数字3の画像を縦nx枚，横ny枚ずつ，計 nx*ny 枚描画
for i in range(ny):
    for j in range(nx):
        plt.subplot(ny, nx, i + ny*j + 1)
        plt.axis('off') # 軸は描画しない
        img = np.reshape(X3[i+ny*j,:],(16,16))
        plt.imshow(img, cmap=plt.cm.gray_r) # 白黒を反転し描画


#plt.savefig('lots_of_3.png')
plt.savefig('lots_of_3.pdf')

plt.show() # 描画した内容を画面表示
