Image Browser

This example shows how to browse through a set of images with a slider.


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt

In [2]:
from ipywidgets import interact

In [3]:
from sklearn import datasets


/usr/local/lib/python3.7/site-packages/sklearn/utils/__init__.py:4: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sequence

We will use the digits dataset from scikit-learn.


In [4]:
digits = datasets.load_digits()

In [5]:
def browse_images(digits):
    n = len(digits.images)
    def view_image(i):
        plt.imshow(digits.images[i], cmap=plt.cm.gray_r, interpolation='nearest')
        plt.title('Training: %s' % digits.target[i])
        plt.show()
    interact(view_image, i=(0,n-1))

In [6]:
browse_images(digits)



In [ ]: