{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# NCL_xy_3.py\nThis script illustrates the following concepts:\n   - Reversing the Y axis\n   - Changing the line dash pattern in an XY plot\n   - Creating your own line dash pattern for an XY plot\n   - Changing the line color and thickness in an XY plot\n   - Creating a vertical profile plot\n\nSee following URLs to see the reproduced NCL plot & script:\n    - Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/xy_3.ncl\n    - Original NCL plots: https://www.ncl.ucar.edu/Applications/Images/xy_3_1_lg.png and https://www.ncl.ucar.edu/Applications/Images/xy_3_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 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/atmos.nc\"), decode_times=False)\nds = ds.U\nds = ds.isel(time=0).drop('time')\nds = ds.isel(lon=0).drop('lon')\nds = ds.isel(lat=42).drop('lat')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Generate figure (set its size (width, height) in inches) and axes\nplt.figure(figsize=(8, 8))\nax = plt.gca()\n\n# Plot data\nplt.plot(ds.data, ds.lev)\n\n# Use geocat.viz.util convenience function to add minor and major tick lines\ngvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=4)\n\n# Use geocat.viz.util convenience function to set axes parameters\ngvutil.set_axes_limits_and_ticks(ax,\n                                 ylim=(1000, 0),\n                                 xticks=np.arange(-10, 30, 5))\n\n# Use geocat.viz.util convenience function to set titles and labels\ngvutil.set_titles_and_labels(ax,\n                             maintitle=\"Profile Plot\",\n                             xlabel=ds.long_name,\n                             ylabel=ds['lev'].long_name)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Generate figure (set its size (width, height) in inches) and axes\nplt.figure(figsize=(8, 8))\nax = plt.gca()\n\n# Plot data with custom line characterisitcs\n# Use keyword `color` to change the line color\n# Use keyword `linewidth` to change the line thickness\n# Use keyword `dashes` to create a custom dash pattern\n# Use keyword `dash_capstyle` to change the shape of the dash end\nplt.plot(ds.data,\n         ds.lev,\n         color='red',\n         linewidth=3,\n         dashes=[3, 2, 1, 2, 1, 2, 1, 2],\n         dash_capstyle='round')\n\n# Use geocat.viz.util convenience function to add minor and major tick lines\ngvutil.add_major_minor_ticks(ax, x_minor_per_major=5, y_minor_per_major=4)\n\n# Use geocat.viz.util convenience function to set axes parameters\ngvutil.set_axes_limits_and_ticks(ax,\n                                 ylim=(1000, 0),\n                                 xticks=np.arange(-10, 30, 5))\n\n# Use geocat.viz.util convenience function to set titles and labels\ngvutil.set_titles_and_labels(ax,\n                             maintitle=\"Make your own dash pattern\",\n                             xlabel=ds.long_name,\n                             ylabel=ds['lev'].long_name)\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
}