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

main
Aurélien Geron 2019-01-16 23:42:53 +08:00
parent d2518a679b
commit 10c432a997
1 changed files with 9 additions and 8 deletions

View File

@ -20,7 +20,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)."
]
},
{
@ -29,8 +29,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",
@ -41,11 +42,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",
@ -1337,7 +1338,7 @@
" coeffs = silhouette_coefficients[y_pred == i]\n",
" coeffs.sort()\n",
"\n",
" color = matplotlib.cm.Spectral(i / k)\n",
" color = mpl.cm.Spectral(i / k)\n",
" plt.fill_betweenx(np.arange(pos, pos + len(coeffs)), 0, coeffs,\n",
" facecolor=color, edgecolor=color, alpha=0.7)\n",
" ticks.append(pos + len(coeffs) // 2)\n",