{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# NCL_conwomap_1.py\nThis script illustrates the following concepts:\n   - Drawing a simple line contour plot\n   - Drawing a line contour plot with multiple colors\n   - Increasing the thickness of contour lines\n\nSee following URLs to see the reproduced NCL plot & script:\n    - Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/conwomap_1.ncl\n    - Original NCL plot: https://www.ncl.ucar.edu/Applications/Images/conwomap_1_2_lg.png\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import packages:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport xarray as xr\nimport matplotlib.pyplot as plt\n\nimport geocat.datafiles as gdf\nfrom geocat.viz import cmaps as gvcmaps\nfrom geocat.viz import util as gvutil"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Read in data:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Open a netCDF data file using xarray default engine and load the data into xarrays\nds = xr.open_dataset(gdf.get(\"netcdf_files/cone.nc\"))\nu = ds.u.isel(time=4)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot Without Enhancements:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "#create figure\nplt.figure(figsize=(10, 10))\n\n#create axes\nax = plt.axes()\nax.set_aspect(1.5)\n\n#contour plot data\np = u.plot.contour(ax=ax,\n                   vmin=0,\n                   vmax=10,\n                   levels=11,\n                   add_labels=False,\n                   colors=\"black\")\n\n#label contours\nax.clabel(p, np.arange(0, 9, 2), colors='black', fmt=\"%.0f\")\n\n# Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions\ngvutil.set_axes_limits_and_ticks(ax,\n                                 xlim=(0, 49),\n                                 ylim=(0, 29),\n                                 xticks=np.linspace(0, 40, 5),\n                                 yticks=np.linspace(0, 25, 6))\n\n# Use geocat.viz.util convenience function to add minor and major tick lines\ngvutil.add_major_minor_ticks(ax,\n                             x_minor_per_major=5,\n                             y_minor_per_major=5,\n                             labelsize=16)\n\n# Use geocat.viz.util convenience function to add titles to left and right of the plot axis.\ngvutil.set_titles_and_labels(ax,\n                             lefttitle=\"Cone amplitude\",\n                             lefttitlefontsize=18,\n                             righttitle=\"ndim\",\n                             righttitlefontsize=18,\n                             xlabel=\"X\",\n                             ylabel=\"Y\",\n                             labelfontsize=18)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot With Enhancements:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Make this figure the thumbnail image on the HTML page.\n# sphinx_gallery_thumbnail_number = 2\n\n#create figure\nplt.figure(figsize=(10, 10))\n\n#create axes\nax = plt.axes()\nax.set_aspect(1.5)\n\n#import colormap\nnewcmp = gvcmaps.NCV_jet\n\n#contour plot data\np = u.plot.contour(ax=ax,\n                   vmin=0,\n                   vmax=10,\n                   levels=11,\n                   cmap=newcmp,\n                   add_labels=False,\n                   linewidths=2.3)\n\n#label contours\nax.clabel(p, np.arange(0, 9, 2), colors='black', fmt=\"%.0f\")\n\n# Use geocat.viz.util convenience function to set axes limits & tick values without calling several matplotlib functions\ngvutil.set_axes_limits_and_ticks(ax,\n                                 xlim=(0, 49),\n                                 ylim=(0, 29),\n                                 xticks=np.linspace(0, 40, 5),\n                                 yticks=np.linspace(0, 25, 6))\n\n# Use geocat.viz.util convenience function to add minor and major tick lines\ngvutil.add_major_minor_ticks(ax,\n                             x_minor_per_major=5,\n                             y_minor_per_major=5,\n                             labelsize=16)\n\n# Use geocat.viz.util convenience function to add titles to left and right of the plot axis.\ngvutil.set_titles_and_labels(ax,\n                             lefttitle=\"Cone amplitude\",\n                             lefttitlefontsize=18,\n                             righttitle=\"ndim\",\n                             righttitlefontsize=18,\n                             xlabel=\"X\",\n                             ylabel=\"Y\",\n                             labelfontsize=18)\n\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}