Skip to content

Commit

Permalink
Make font sizes consistent across notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Nov 27, 2021
1 parent e72b210 commit 52d4f0a
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 156 deletions.
28 changes: 16 additions & 12 deletions 01_the_machine_learning_landscape.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To plot pretty figures directly within Jupyter:"
"Let's define the default font sizes, to plot pretty figures:"
]
},
{
Expand All @@ -104,8 +104,11 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"plt.rc('font', size=12)\n",
"plt.rc('axes', labelsize=14)"
"plt.rc('font', size=14)\n",
"plt.rc('axes', labelsize=14, titlesize=14)\n",
"plt.rc('legend', fontsize=14)\n",
"plt.rc('xtick',labelsize=10)\n",
"plt.rc('ytick',labelsize=10)"
]
},
{
Expand Down Expand Up @@ -403,11 +406,12 @@
"max_life_sat = 9\n",
"\n",
"position_text = {\n",
" \"Hungary\": (28_000, 4.2),\n",
" \"Turkey\": (29_500, 4.2),\n",
" \"Hungary\": (28_000, 6.9),\n",
" \"France\": (40_000, 5),\n",
" \"New Zealand\": (28_000, 8.2),\n",
" \"Australia\": (50_000, 5.5),\n",
" \"United States\": (59_000, 5.5),\n",
" \"United States\": (59_000, 5.3),\n",
" \"Denmark\": (46_000, 8.5)\n",
"}\n",
"\n",
Expand All @@ -416,7 +420,7 @@
" pos_data_y = country_stats[lifesat_col].loc[country]\n",
" country = \"U.S.\" if country == \"United States\" else country\n",
" plt.annotate(country, xy=(pos_data_x, pos_data_y),\n",
" xytext=pos_text,\n",
" xytext=pos_text, fontsize=12,\n",
" arrowprops=dict(facecolor='black', width=0.5,\n",
" shrink=0.15, headwidth=5))\n",
" plt.plot(pos_data_x, pos_data_y, \"ro\")\n",
Expand Down Expand Up @@ -499,9 +503,9 @@
"X = np.linspace(min_gdp, max_gdp, 1000)\n",
"plt.plot(X, t0 + t1 * X, \"b\")\n",
"\n",
"plt.text(max_gdp - 20_000, min_life_sat + 1.5,\n",
"plt.text(max_gdp - 20_000, min_life_sat + 1.9,\n",
" fr\"$\\theta_0 = {t0:.2f}$\", color=\"b\")\n",
"plt.text(max_gdp - 20_000, min_life_sat + 1,\n",
"plt.text(max_gdp - 20_000, min_life_sat + 1.3,\n",
" fr\"$\\theta_1 = {t1 * 1e5:.2f} \\times 10^{{-5}}$\", color=\"b\")\n",
"\n",
"plt.axis([min_gdp, max_gdp, min_life_sat, max_life_sat])\n",
Expand Down Expand Up @@ -542,9 +546,9 @@
"X = np.linspace(min_gdp, max_gdp, 1000)\n",
"plt.plot(X, t0 + t1 * X, \"b\")\n",
"\n",
"plt.text(min_gdp + 15_000, max_life_sat - 1.5,\n",
"plt.text(min_gdp + 22_000, max_life_sat - 1.1,\n",
" fr\"$\\theta_0 = {t0:.2f}$\", color=\"b\")\n",
"plt.text(min_gdp + 15_000, max_life_sat - 1,\n",
"plt.text(min_gdp + 22_000, max_life_sat - 0.6,\n",
" fr\"$\\theta_1 = {t1 * 1e5:.2f} \\times 10^{{-5}}$\", color=\"b\")\n",
"\n",
"plt.plot([cyprus_gdp_per_capita, cyprus_gdp_per_capita],\n",
Expand Down Expand Up @@ -600,7 +604,7 @@
"for country, pos_text in position_text_missing_countries.items():\n",
" pos_data_x, pos_data_y = missing_data.loc[country]\n",
" plt.annotate(country, xy=(pos_data_x, pos_data_y),\n",
" xytext=pos_text,\n",
" xytext=pos_text, fontsize=12,\n",
" arrowprops=dict(facecolor='black', width=0.5,\n",
" shrink=0.1, headwidth=5))\n",
" plt.plot(pos_data_x, pos_data_y, \"rs\")\n",
Expand Down Expand Up @@ -694,7 +698,7 @@
"t0ridge, t1ridge = ridge.intercept_[0], ridge.coef_[0][0]\n",
"plt.plot(X, t0ridge + t1ridge * X, \"b--\",\n",
" label=\"Regularized linear model on partial data\")\n",
"plt.legend(loc=\"lower right\")\n",
"plt.legend(loc=\"lower right\", fontsize=13)\n",
"\n",
"plt.axis([0, 115_000, min_life_sat, max_life_sat])\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion 02_end_to_end_machine_learning_project.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"import matplotlib.pyplot as plt\n",
"\n",
"# not in the book – the next 5 lines define the default font sizes\n",
"plt.rc('font', size=12)\n",
"plt.rc('font', size=14)\n",
"plt.rc('axes', labelsize=14, titlesize=14)\n",
"plt.rc('legend', fontsize=14)\n",
"plt.rc('xtick',labelsize=10)\n",
Expand Down
Loading

0 comments on commit 52d4f0a

Please sign in to comment.