|
46 | 46 | "\n", |
47 | 47 | "nx, ny = 6, 3\n", |
48 | 48 | "\n", |
49 | | - "np.random.seed(0)\n", |
50 | | - "orography = np.random.normal(1000, 600, size=(ny, nx)) - 400\n", |
51 | | - "sea_level_temp = np.random.normal(290, 5, size=(ny, nx))" |
| 49 | + "rng = np.random.default_rng(0)\n", |
| 50 | + "orography = rng.normal(1000, 600, size=(ny, nx)) - 400\n", |
| 51 | + "sea_level_temp = rng.normal(290, 5, size=(ny, nx))" |
52 | 52 | ] |
53 | 53 | }, |
54 | 54 | { |
|
85 | 85 | "\n", |
86 | 86 | "import matplotlib.pyplot as plt\n", |
87 | 87 | "\n", |
88 | | - "plt.set_cmap('viridis')\n", |
| 88 | + "plt.set_cmap(\"viridis\")\n", |
89 | 89 | "fig = plt.figure(figsize=(8, 6))\n", |
90 | 90 | "\n", |
91 | 91 | "plt.subplot(1, 2, 1)\n", |
92 | 92 | "plt.pcolormesh(orography)\n", |
93 | | - "cbar = plt.colorbar(orientation='horizontal',\n", |
94 | | - " label='Orography (m)')\n", |
| 93 | + "cbar = plt.colorbar(orientation=\"horizontal\",\n", |
| 94 | + " label=\"Orography (m)\")\n", |
95 | 95 | "# Reduce the maximum number of ticks to 5.\n", |
96 | 96 | "cbar.ax.xaxis.get_major_locator().nbins = 5\n", |
97 | 97 | "\n", |
98 | 98 | "plt.subplot(1, 2, 2)\n", |
99 | 99 | "plt.pcolormesh(sea_level_temp)\n", |
100 | | - "cbar = plt.colorbar(orientation='horizontal',\n", |
101 | | - " label='Sea level temperature (K)')\n", |
| 100 | + "cbar = plt.colorbar(orientation=\"horizontal\",\n", |
| 101 | + " label=\"Sea level temperature (K)\")\n", |
102 | 102 | "# Reduce the maximum number of ticks to 5.\n", |
103 | 103 | "cbar.ax.xaxis.get_major_locator().nbins = 5\n", |
104 | 104 | "\n", |
|
179 | 179 | "source": [ |
180 | 180 | "plt.figure(figsize=(8, 6))\n", |
181 | 181 | "plt.fill_between(np.arange(6), np.zeros(6), orography[1, :],\n", |
182 | | - " color='green', linewidth=2, label='Orography')\n", |
| 182 | + " color=\"green\", linewidth=2, label=\"Orography\")\n", |
183 | 183 | "\n", |
184 | 184 | "plt.plot(np.zeros(nx),\n", |
185 | | - " color='blue', linewidth=1.2,\n", |
186 | | - " label='Sea level')\n", |
| 185 | + " color=\"blue\", linewidth=1.2,\n", |
| 186 | + " label=\"Sea level\")\n", |
187 | 187 | "\n", |
188 | 188 | "for i in range(9):\n", |
189 | | - " plt.plot(altitude[i, 1, :], color='gray', linestyle='--',\n", |
190 | | - " label='Model levels' if i == 0 else None)\n", |
| 189 | + " plt.plot(altitude[i, 1, :], color=\"gray\", linestyle=\"--\",\n", |
| 190 | + " label=\"Model levels\" if i == 0 else None)\n", |
191 | 191 | "\n", |
192 | | - "plt.ylabel('altitude / m')\n", |
| 192 | + "plt.ylabel(\"altitude / m\")\n", |
193 | 193 | "plt.margins(0.1)\n", |
194 | 194 | "plt.legend()\n", |
195 | 195 | "plt.show()" |
|
250 | 250 | } |
251 | 251 | ], |
252 | 252 | "source": [ |
253 | | - "from matplotlib.colors import LogNorm\n", |
254 | | - "\n", |
255 | 253 | "fig = plt.figure(figsize=(8, 6))\n", |
256 | 254 | "norm = plt.Normalize(vmin=temperature.min(), vmax=temperature.max())\n", |
257 | 255 | "\n", |
258 | 256 | "for i in range(nz):\n", |
259 | 257 | " plt.subplot(3, 3, i + 1)\n", |
260 | | - " qm = plt.pcolormesh(temperature[i], cmap='viridis', norm=norm)\n", |
| 258 | + " qm = plt.pcolormesh(temperature[i], cmap=\"viridis\", norm=norm)\n", |
261 | 259 | "\n", |
262 | 260 | "plt.subplots_adjust(right=0.84, wspace=0.3, hspace=0.3)\n", |
263 | 261 | "cax = plt.axes([0.85, 0.1, 0.03, 0.8])\n", |
|
332 | 330 | "source": [ |
333 | 331 | "plt.figure(figsize=(8, 6))\n", |
334 | 332 | "plt.fill_between(np.arange(6), np.zeros(6), orography[1, :],\n", |
335 | | - " color='green', linewidth=2, label='Orography')\n", |
| 333 | + " color=\"green\", linewidth=2, label=\"Orography\")\n", |
336 | 334 | "\n", |
337 | 335 | "for i in range(9):\n", |
338 | 336 | " plt.plot(altitude[i, 1, :],\n", |
339 | | - " color='gray', lw=1.2,\n", |
340 | | - " label=None if i > 0 else 'Source levels \\n(model levels)')\n", |
| 337 | + " color=\"gray\", lw=1.2,\n", |
| 338 | + " label=None if i > 0 else \"Source levels \\n(model levels)\")\n", |
341 | 339 | "for i, target in enumerate(target_altitudes):\n", |
342 | 340 | " plt.plot(np.repeat(target, 6),\n", |
343 | | - " color='gray', linestyle='--', lw=1.4, alpha=0.6,\n", |
344 | | - " label=None if i > 0 else 'Target levels \\n(altitude)')\n", |
| 341 | + " color=\"gray\", linestyle=\"--\", lw=1.4, alpha=0.6,\n", |
| 342 | + " label=None if i > 0 else \"Target levels \\n(altitude)\")\n", |
345 | 343 | "\n", |
346 | | - "plt.ylabel('height / m')\n", |
| 344 | + "plt.ylabel(\"height / m\")\n", |
347 | 345 | "plt.margins(top=0.1)\n", |
348 | 346 | "plt.legend()\n", |
349 | | - "plt.savefig('summary.png')\n", |
| 347 | + "plt.savefig(\"summary.png\")\n", |
350 | 348 | "plt.show()" |
351 | 349 | ] |
352 | 350 | }, |
|
413 | 411 | "plt.figure(figsize=(8, 6))\n", |
414 | 412 | "ax1 = plt.subplot(1, 2, 1)\n", |
415 | 413 | "plt.fill_between(np.arange(6), np.zeros(6), orography[1, :],\n", |
416 | | - " color='green', linewidth=2, label='Orography')\n", |
| 414 | + " color=\"green\", linewidth=2, label=\"Orography\")\n", |
417 | 415 | "cs = plt.contourf(np.tile(np.arange(6), nz).reshape(nz, 6),\n", |
418 | 416 | " altitude[:, 1],\n", |
419 | 417 | " temperature[:, 1])\n", |
|
423 | 421 | "\n", |
424 | 422 | "plt.subplot(1, 2, 2, sharey=ax1)\n", |
425 | 423 | "plt.fill_between(np.arange(6), np.zeros(6), orography[1, :],\n", |
426 | | - " color='green', linewidth=2, label='Orography')\n", |
| 424 | + " color=\"green\", linewidth=2, label=\"Orography\")\n", |
427 | 425 | "plt.contourf(np.arange(6), target_altitudes,\n", |
428 | 426 | " np.ma.masked_invalid(new_temperature[:, 1]),\n", |
429 | 427 | " cmap=cs.cmap, norm=cs.norm)\n", |
|
432 | 430 | " c=new_temperature[:, 1])\n", |
433 | 431 | "plt.scatter(np.tile(np.arange(nx), target_nz).reshape(target_nz, nx),\n", |
434 | 432 | " np.repeat(target_altitudes, nx).reshape(target_nz, nx),\n", |
435 | | - " s=np.isnan(new_temperature[:, 1]) * 15, marker='x')\n", |
| 433 | + " s=np.isnan(new_temperature[:, 1]) * 15, marker=\"x\")\n", |
436 | 434 | "\n", |
437 | | - "plt.suptitle('Temperature cross-section before and after restratification')\n", |
| 435 | + "plt.suptitle(\"Temperature cross-section before and after restratification\")\n", |
438 | 436 | "plt.show()" |
439 | 437 | ] |
440 | 438 | } |
|
0 commit comments