From 10c432a997fbb53d2ca05778a94ef2869e440ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Wed, 16 Jan 2019 23:42:53 +0800 Subject: [PATCH] Drop Python 2 (woohoo!) and import matplotlib as mpl --- 09_unsupervised_learning.ipynb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/09_unsupervised_learning.ipynb b/09_unsupervised_learning.ipynb index 591680d..cedcbe1 100644 --- a/09_unsupervised_learning.ipynb +++ b/09_unsupervised_learning.ipynb @@ -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",