LOADING IMAGES IN MATPLOTLIB
Listing 5.11 displays the content of load_images2.py that illustrates how to display an image.
LISTING 5.11: load_images2.py
from sklearn.datasets import load_digits from matplotlib import pyplot as plt digits = load_digits() #set interpolation='none' fig = plt.figure(figsize=(3, 3)) plt.imshow(digits['images'][66], cmap="gray", interpolation='none') plt.show()
Listing 5.11 starts with two import statements, and then the digits variable is initialized with the contents of the digits dataset. The next portion of Listing 5.11 displays the contents of one of the images in the digits dataset. Launch the code in Listing 5.11, and you will see the image in Figure 5.8.

FIGURE 5.8 Loading an image in Matplotlib