mirror of
https://github.com/ArthurDanjou/handson-ml3.git
synced 2026-01-14 12:14:36 +01:00
Make font sizes consistent across notebooks
This commit is contained in:
@@ -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:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user