From a275386548e51e9ddc0bfac2180ed2ca3dd32ea4 Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:09:33 -0700 Subject: [PATCH 1/2] add template --- plot_types/template.ipynb | 234 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 plot_types/template.ipynb diff --git a/plot_types/template.ipynb b/plot_types/template.ipynb new file mode 100644 index 00000000..3d5b2172 --- /dev/null +++ b/plot_types/template.ipynb @@ -0,0 +1,234 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Plot Template\n", + "\n", + "Brief description of this type of plot.\n", + "\n", + "In geoscience, how is this plot used? Are there certain datasets more typically used with this type of plot?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import xarray as xr\n", + "import cartopy.crs as ccrs\n", + "import cartopy.feature as cfeature\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import geocat.datafiles as gdf" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Get Relevant Dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Use Xarray and GeoCAT datafiles to pull up a sample relevant dataset\n", + "ds = xr.open_dataset(gdf.get(\"\"), decode_times=False)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Simple Plot\n", + "\n", + "The simplest way to create any of this type of plot plot is simply to call up ``." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Base Case" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Generate figure (set its size (width, height) in inches)\n", + "fig, ax = plt.subplots(figsize=(8, 6))\n", + "\n", + "# Plot the data in one line if possible.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Simple Customizations\n", + "\n", + "In this example we demonstrate:\n", + "- setting differnt kwargs with `a=1`.\n", + "\n", + "Check out [Matplotlib's `plot-type` documentation]() to see all the keyword argument customization options available to you." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Generate figure (set its size (width, height) in inches)\n", + "fig, ax = plt.subplots(figsize=(8, 6))\n", + "\n", + "# Plot the data with relevant kwargs specified." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plot with Cartopy\n", + "\n", + "If relevant, demonstrate how to plot data on a map. Talk about why this data should be on a map.\n", + "\n", + "In the below example, we demonstrate adding Cartopy Plate Carree axes, land features, and lat-lon gridlines.\n", + "\n", + "What is new in this plot? Don't do all of the Cartopy customization yet, just the bare minimum to make the map look as expected." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Generate figure (set its size (width, height) in inches) and axes using Cartopy projection\n", + "fig = plt.figure(figsize=(8, 6))\n", + "\n", + "# Generate axes using Cartopy\n", + "ax = plt.axes(projection=ccrs.PlateCarree())\n", + "\n", + "# Turn on continent shading\n", + "ax.add_feature(cfeature.LAND,\n", + " zorder=0)\n", + "\n", + "# Plot the data on the map\n", + "\n", + "plt.title(\"\");" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Cartopy Customization\n", + "\n", + "You can change the way your Cartopy plot looks with the inclusion of `edgecolor` and `facecolor` specifications. Light gray tends to look nice." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Generate figure (set its size (width, height) in inches) and axes using Cartopy projection\n", + "fig = plt.figure(figsize=(8, 6))\n", + "\n", + "# Generate axes using Cartopy\n", + "ax = plt.axes(projection=ccrs.PlateCarree())\n", + "\n", + "# Turn on continent shading\n", + "ax.add_feature(cfeature.LAND,\n", + " edgecolor='lightgray',\n", + " facecolor='lightgray',\n", + " zorder=0)\n", + "\n", + "# Plot the data on the map\n", + "\n", + "plt.title(\"\");" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Another layer of information on the plot\n", + "\n", + "If your plot can be customized to display more information, now is the time to demonstrate that. Go through default then customization steps for each new thing (such as colorbars) that you add." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Finishing Touches" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Grid Lines\n", + "\n", + "Does this plot benefit from gridlines? Add them now and talk about it." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Titles and Labels\n", + "\n", + "All plots should have an informative title. In this final step we add a title to our plot and turn off the redundant top and right gridlabels." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "geocat-applications", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} From fe6b38188134919f663aaf6f6a79c7d1e3c4ed42 Mon Sep 17 00:00:00 2001 From: Julia Kent <46687291+jukent@users.noreply.github.com> Date: Wed, 20 Dec 2023 09:27:41 -0700 Subject: [PATCH 2/2] at references section to template --- plot_types/template.ipynb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plot_types/template.ipynb b/plot_types/template.ipynb index 3d5b2172..3bc7730b 100644 --- a/plot_types/template.ipynb +++ b/plot_types/template.ipynb @@ -207,6 +207,18 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## References\n", + "\n", + "Want to go deeper in your understanding of the topic or the available keyword arguments, check out these resources:\n", + "\n", + " - [Link to Documentation]()\n", + " - [Another link]()" + ] } ], "metadata": {