From 692c9ec9ab86e3f9d5df40f79fcec8e50e6b7965 Mon Sep 17 00:00:00 2001 From: Caroline Arnold <arnold@dkrz.de> Date: Wed, 8 Mar 2023 08:03:53 +0100 Subject: [PATCH] revised visualization notebooks --- .../visualization_with_Matplotlib_L1.ipynb | 20 ++++++++++--------- .../visualization_with_Matplotlib_L2.ipynb | 15 +++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/notebooks/visualization_with_Matplotlib_L1.ipynb b/notebooks/visualization_with_Matplotlib_L1.ipynb index dfc3881..c203092 100644 --- a/notebooks/visualization_with_Matplotlib_L1.ipynb +++ b/notebooks/visualization_with_Matplotlib_L1.ipynb @@ -184,7 +184,7 @@ "\n", " [<matplotlib.lines.Line2D at 0x10f402500>]\n", " \n", - "from above you can write it to a variable:" + "from above you can add a semicolon to the line or write the expression to a variable." ] }, { @@ -193,7 +193,7 @@ "metadata": {}, "outputs": [], "source": [ - "yplot = plt.plot(y)" + "plt.plot(y);" ] }, { @@ -444,7 +444,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Sometimes you want to overlay different components of your plots using transparency. In matplotlib this is achieved by setting the transparency parameter `alpha`. Here, `alpha=1.` corresponds to full **opacity**, and `alpha=0.` to **full transparency**. In the following plot, we draw a transparent line on top of a solid line:" + "Sometimes you want to overlay different components of your plots using transparency. In matplotlib this is achieved by setting the transparency parameter `alpha`. Here, `alpha=1.` corresponds to full **opacity**, and `alpha=0.` to **full transparency**. In the following plot, we draw a black transparent line on top of a solid red line:" ] }, { @@ -454,8 +454,8 @@ "outputs": [], "source": [ "plt.grid()\n", - "plt.plot(x, y, 'ko-', linewidth=2, alpha=0.2)\n", - "plt.plot(x, [v**2/2 for v in y], 'rs:', linewidth=2)" + "plt.plot(x, [v**2/2 for v in y], 'rs:', linewidth=2)\n", + "plt.plot(x, y, 'ko-', linewidth=2, alpha=0.2)" ] }, { @@ -611,7 +611,9 @@ "In the next section we demonstrate how to use `pyplot.subplots` functionality to create two plots in one workspace.\n", "\n", "1. two plots in one row\n", - "1. common title on top of the figure\n" + "1. common title on top of the figure\n", + "\n", + "Note that `axs` is now an array, and we access the individual axes by indexing it." ] }, { @@ -1183,9 +1185,9 @@ ], "metadata": { "kernelspec": { - "display_name": "cartopy", + "display_name": "CyGNSS Deployment", "language": "python", - "name": "cartopy" + "name": "cygnss-d" }, "language_info": { "codemirror_mode": { @@ -1197,7 +1199,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/notebooks/visualization_with_Matplotlib_L2.ipynb b/notebooks/visualization_with_Matplotlib_L2.ipynb index ec9eac9..cfb4099 100644 --- a/notebooks/visualization_with_Matplotlib_L2.ipynb +++ b/notebooks/visualization_with_Matplotlib_L2.ipynb @@ -128,7 +128,7 @@ "\n", "## Add a legend <a class=\"anchor\" id=\"add-legend\"></a>\n", "\n", - "This looks quite nice, but a legend is still missing. Therefore, a **label** has to be added to each plot call and the `legend` fuction from pyplot is used to generate a legend box at the upper left part of the plot (default).\n", + "This looks quite nice, but a legend is still missing. Therefore, a **label** has to be added to each plot call and the `legend` fuction from pyplot is used to generate a legend box. By default, the legend is placed in a location where it does not overlap the plot, that can be changed by specifying the `loc` parameter.\n", "\n", "<br>" ] @@ -151,7 +151,6 @@ "ax.plot(data.Jahr, data['Bayern'], color='darkorange', label='Bayern')\n", "\n", "legend = ax.legend()\n", - "#legend = ax.legend(facecolor='lightgray')\n", "#legend = ax.legend(loc='lower right', shadow=True, fontsize='small', \n", "# facecolor='lightgray', edgecolor='black')\n", "\n", @@ -320,7 +319,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Another way to create the plot:" + "Another way to create the axis in one line of code:" ] }, { @@ -577,7 +576,7 @@ " levels=15, transform=ccrs.PlateCarree())\n", "\n", "cbar = plt.colorbar(plt_cn, pad=0.08, shrink=0.55)\n", - "cbar.set_label('$^o$ C', labelpad=15, y=.5, rotation=270)" + "cbar.set_label('Surface temperature $(^\\circ\\mathrm{C})$', labelpad=15, y=.5, rotation=90)" ] }, { @@ -699,7 +698,7 @@ " transform=ccrs.PlateCarree())\n", "\n", "cbar = plt.colorbar(vec, pad=0.07, shrink=0.55)\n", - "cbar.set_label('Wind magnitude (m/s)', labelpad=15, y=.5, rotation=270)" + "cbar.set_label('Wind magnitude (m/s)', labelpad=15, y=.5, rotation=90)" ] }, { @@ -933,9 +932,9 @@ ], "metadata": { "kernelspec": { - "display_name": "cartopy", + "display_name": "ML (based on the latest module pytorch)", "language": "python", - "name": "cartopy" + "name": "ml-aim" }, "language_info": { "codemirror_mode": { @@ -947,7 +946,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.10.8" } }, "nbformat": 4, -- GitLab