Drop Python 2 (woohoo!) and import matplotlib as mpl
parent
d2518a679b
commit
10c432a997
|
@ -20,7 +20,7 @@
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"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": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# To support both python 2 and python 3\n",
|
"# Python ≥3.5 is required\n",
|
||||||
"from __future__ import division, print_function, unicode_literals\n",
|
"import sys\n",
|
||||||
|
"assert sys.version_info >= (3, 5)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Common imports\n",
|
"# Common imports\n",
|
||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
|
@ -41,11 +42,11 @@
|
||||||
"\n",
|
"\n",
|
||||||
"# To plot pretty figures\n",
|
"# To plot pretty figures\n",
|
||||||
"%matplotlib inline\n",
|
"%matplotlib inline\n",
|
||||||
"import matplotlib\n",
|
"import matplotlib as mpl\n",
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"plt.rcParams['axes.labelsize'] = 14\n",
|
"mpl.rc('axes', labelsize=14)\n",
|
||||||
"plt.rcParams['xtick.labelsize'] = 12\n",
|
"mpl.rc('xtick', labelsize=12)\n",
|
||||||
"plt.rcParams['ytick.labelsize'] = 12\n",
|
"mpl.rc('ytick', labelsize=12)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Where to save the figures\n",
|
"# Where to save the figures\n",
|
||||||
"PROJECT_ROOT_DIR = \".\"\n",
|
"PROJECT_ROOT_DIR = \".\"\n",
|
||||||
|
@ -1337,7 +1338,7 @@
|
||||||
" coeffs = silhouette_coefficients[y_pred == i]\n",
|
" coeffs = silhouette_coefficients[y_pred == i]\n",
|
||||||
" coeffs.sort()\n",
|
" coeffs.sort()\n",
|
||||||
"\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",
|
" plt.fill_betweenx(np.arange(pos, pos + len(coeffs)), 0, coeffs,\n",
|
||||||
" facecolor=color, edgecolor=color, alpha=0.7)\n",
|
" facecolor=color, edgecolor=color, alpha=0.7)\n",
|
||||||
" ticks.append(pos + len(coeffs) // 2)\n",
|
" ticks.append(pos + len(coeffs) // 2)\n",
|
||||||
|
|
Loading…
Reference in New Issue