Skip to content

Instantly share code, notes, and snippets.

@udoprog
Last active October 19, 2017 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udoprog/a37deae537270832c436d825f29aadd5 to your computer and use it in GitHub Desktop.
Save udoprog/a37deae537270832c436d825f29aadd5 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata("MNIST original")
def plot_images(datas, titles):
fig, axes = plt.subplots(4, int(len(datas) / 4))
fig.set_size_inches((10, 10))
for data, title, ax in zip(datas, titles, axes.ravel()):
img = np.reshape(data, [28, 28])
ax.set_title(str(title))
ax.imshow(img, cmap=plt.cm.gray)
ax.set_xticks(())
ax.set_yticks(())
fig.tight_layout()
plt.show()
indexes = np.random.choice(len(mnist.data), 4 * 4)
plot_images(mnist.data[indexes], mnist.target[indexes])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment