notebook/examples/Interactive Widgets/Image Browser.ipynb

124 lines
17 KiB
Plaintext
Raw Normal View History

2014-03-12 04:17:17 +08:00
{
"metadata": {
"name": "",
"signature": "sha256:4e9f4ce8fa9be2e33ffdae399daec11bf3ef63a6f0065b1d59739310ebfe8008"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Image Browser"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example shows how to browse through a set of images with a slider."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.html.widgets import interact"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from sklearn import datasets"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will use the digits dataset from [scikit-learn](http://scikit-learn.org/stable/)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"digits = datasets.load_digits()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def browse_images(digits):\n",
" n = len(digits.images)\n",
" def view_image(i):\n",
" plt.imshow(digits.images[i], cmap=plt.cm.gray_r, interpolation='nearest')\n",
" plt.title('Training: %s' % digits.target[i])\n",
" plt.show()\n",
" interact(view_image, i=(0,n-1))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"browse_images(digits)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {
"png": {
"height": 390,
"width": 370
}
},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAuUAAAMNCAYAAAA/WgqlAAAAB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