|
26 | 26 | "import numpy as np\n", |
27 | 27 | "import pandas as pd\n", |
28 | 28 | "\n", |
29 | | - "mpl.rcParams['pdf.fonttype'] = 42\n", |
30 | | - "mpl.rcParams['ps.fonttype'] = 42" |
| 29 | + "mpl.rcParams[\"pdf.fonttype\"] = 42\n", |
| 30 | + "mpl.rcParams[\"ps.fonttype\"] = 42" |
31 | 31 | ] |
32 | 32 | }, |
33 | 33 | { |
|
105 | 105 | "x = mu + sigma * np.random.randn(10000)\n", |
106 | 106 | "fig, ax = plt.subplots(figsize=(5, 2.7), layout=\"constrained\")\n", |
107 | 107 | "# the histogram of the data\n", |
108 | | - "n, bins, patches = ax.hist(x, 50, density=True, facecolor=\"C0\", alpha=0.75)\n", |
| 108 | + "n, bins, patches = ax.hist(\n", |
| 109 | + " x,\n", |
| 110 | + " 50,\n", |
| 111 | + " density=True,\n", |
| 112 | + " facecolor=\"C0\", # first color in color palette\n", |
| 113 | + " alpha=0.75,\n", |
| 114 | + ")\n", |
109 | 115 | "\n", |
110 | 116 | "ax.set_xlabel(\"Length [cm]\")\n", |
111 | 117 | "ax.set_ylabel(\"Probability\")\n", |
|
141 | 147 | "Y2 = 1 + np.cos(1 + X / 0.75) / 2\n", |
142 | 148 | "Y3 = np.random.uniform(Y1, Y2, len(X))\n", |
143 | 149 | "\n", |
144 | | - "data = {'X': X, 'red_line': Y1, 'blue_line': Y2, 'circles': Y3}\n", |
| 150 | + "data = {\"X\": X, \"red_line\": Y1, \"blue_line\": Y2, \"circles\": Y3}\n", |
145 | 151 | "data = pd.DataFrame(data)\n", |
146 | 152 | "data.head()" |
147 | 153 | ] |
|
175 | 181 | "ax.set_xlim(0, 4)\n", |
176 | 182 | "ax.set_ylim(0, 4)\n", |
177 | 183 | "\n", |
178 | | - "ax.tick_params(which='major', width=1.0, length=10, labelsize=14)\n", |
179 | | - "ax.tick_params(which='minor', width=1.0, length=5, labelsize=10,\n", |
180 | | - " labelcolor='0.25')\n", |
| 184 | + "ax.tick_params(which=\"major\", width=1.0, length=10, labelsize=14)\n", |
| 185 | + "ax.tick_params(which=\"minor\", width=1.0, length=5, labelsize=10, labelcolor=\"0.25\")\n", |
181 | 186 | "\n", |
182 | | - "ax.grid(linestyle=\"--\", linewidth=0.5, color='.25', zorder=-10)\n", |
| 187 | + "ax.grid(linestyle=\"--\", linewidth=0.5, color=\".25\", zorder=-10)\n", |
183 | 188 | "\n", |
184 | | - "ax.plot(X, Y1, c='C0', lw=2.5, label=\"Blue signal\", zorder=10)\n", |
185 | | - "ax.plot(X, Y2, c='C1', lw=2.5, label=\"Orange signal\")\n", |
186 | | - "ax.plot(X[::3], Y3[::3], linewidth=0, markersize=9,\n", |
187 | | - " marker='s', markerfacecolor='none', markeredgecolor='C4',\n", |
188 | | - " markeredgewidth=2.5)\n", |
| 189 | + "ax.plot(X, Y1, c=\"C0\", lw=2.5, label=\"Blue signal\", zorder=10)\n", |
| 190 | + "ax.plot(X, Y2, c=\"C1\", lw=2.5, label=\"Orange signal\")\n", |
| 191 | + "ax.plot(\n", |
| 192 | + " X[::3],\n", |
| 193 | + " Y3[::3],\n", |
| 194 | + " linewidth=0,\n", |
| 195 | + " markersize=9,\n", |
| 196 | + " marker=\"s\",\n", |
| 197 | + " markerfacecolor=\"none\",\n", |
| 198 | + " markeredgecolor=\"C4\", # color 5 in color palette\n", |
| 199 | + " markeredgewidth=2.5,\n", |
| 200 | + ")\n", |
189 | 201 | "\n", |
190 | | - "ax.set_title(\"Anatomy of a figure\", fontsize=20, verticalalignment='bottom')\n", |
| 202 | + "ax.set_title(\"Anatomy of a figure\", fontsize=20, verticalalignment=\"bottom\")\n", |
191 | 203 | "ax.set_xlabel(\"x Axis label\", fontsize=14)\n", |
192 | 204 | "ax.set_ylabel(\"y Axis label\", fontsize=14)\n", |
193 | 205 | "ax.legend(loc=\"upper right\", fontsize=14)" |
|
332 | 344 | "outputs": [], |
333 | 345 | "source": [ |
334 | 346 | "fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(7.4, 4))\n", |
335 | | - "axes = axes.flatten() # in case of more than one dimension (safety snippet for you)\n", |
| 347 | + "axes = axes.flatten() # in case of more than one dimension (safety snippet for you)\n", |
336 | 348 | "ax = axes[0]\n", |
337 | 349 | "n, bins, patches = ax.hist(x, bins=30, alpha=0.7, color=\"C0\")\n", |
338 | 350 | "ax = axes[1]\n", |
|
0 commit comments