Sign in

How to plot MNIST using Matplotlib?

As I mentioned in the last post, We cannot install PyTorch MNIST smoothly.

If you stuck in installing the MNIST, check https://kazma-s-1306.medium.com/in-2021-as-it-turned-out-pytorch-mnist-cannot-be-installed-like-before-8b1083f80086.

1, Plot multiple images

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

2, Plot an individual image

#obtain a batch of training images
idx = 0

If you’d like to get the image black and white in the other way, cmap = ‘gray_r’.

3, Plot an individual image with annotations

img = images[idx].squeeze()

Writer, programmer. Here to show what’s inside my head and to be understood.