Drop Python 2 (woohoo!) and import matplotlib as mpl

This commit is contained in:
Aurélien Geron
2019-01-16 23:42:00 +08:00
parent ca6eb8c147
commit d2518a679b
8 changed files with 223 additions and 259 deletions

View File

@@ -25,7 +25,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let's make sure this notebook works well in both python 2 and 3, import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures:"
"First, let's import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures. We also check that Python 3.5 or later is installed (although Python 2.x may work, it is deprecated so we strongly recommend you use Python 3 instead)."
]
},
{
@@ -34,8 +34,9 @@
"metadata": {},
"outputs": [],
"source": [
"# To support both python 2 and python 3\n",
"from __future__ import division, print_function, unicode_literals\n",
"# Python ≥3.5 is required\n",
"import sys\n",
"assert sys.version_info >= (3, 5)\n",
"\n",
"# Common imports\n",
"import numpy as np\n",
@@ -46,11 +47,11 @@
"\n",
"# To plot pretty figures\n",
"%matplotlib inline\n",
"import matplotlib\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams['axes.labelsize'] = 14\n",
"plt.rcParams['xtick.labelsize'] = 12\n",
"plt.rcParams['ytick.labelsize'] = 12\n",
"mpl.rc('axes', labelsize=14)\n",
"mpl.rc('xtick', labelsize=12)\n",
"mpl.rc('ytick', labelsize=12)\n",
"\n",
"# Where to save the figures\n",
"PROJECT_ROOT_DIR = \".\"\n",
@@ -454,7 +455,7 @@
"source": [
"def plot_digit(data):\n",
" image = data.reshape(28, 28)\n",
" plt.imshow(image, cmap = matplotlib.cm.hot,\n",
" plt.imshow(image, cmap = mpl.cm.hot,\n",
" interpolation=\"nearest\")\n",
" plt.axis(\"off\")"
]
@@ -1336,7 +1337,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 - tf2",
"language": "python",
"name": "python3"
},
@@ -1350,7 +1351,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.6.8"
},
"nav_menu": {
"height": "252px",