{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# NCL_taylor_6.py\n",
    "This script illustrates the following concepts:\n",
    "   - Using geocat-viz [Taylor diagram function](https://geocat-viz.readthedocs.io/en/latest/user_api/generated/geocat.viz.TaylorDiagram.html#geocat.viz.TaylorDiagram) to create a Taylor diagram.\n",
    "   - Labelling a Taylor diagram\n",
    "   - Using subplots\n",
    "\n",
    "See following URLs to see the reproduced NCL plot & script:\n",
    "   - [Original NCL script](https://www.ncl.ucar.edu/Applications/Scripts/taylor_6.ncl)\n",
    "   - [Original NCL plots](https://www.ncl.ucar.edu/Applications/Images/taylor_6_3_lg.png)\n",
    "\n",
    "Note: Due to limitations of matplotlib's axisartist toolkit, we cannot include minor tick marks between 0.9 and 0.99, as seen in the original NCL plot.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import packages:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "import geocat.viz as gv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot:\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "# Create figure\n",
    "fig = plt.figure(figsize=(12, 12))\n",
    "fig.subplots_adjust(wspace=0.3, hspace=0.3)\n",
    "\n",
    "# Create a list of model names\n",
    "namearr = [\"SLP\", \"Tsfc\", \"Prc\", \"Prc 30S-30N\", \"LW\", \"SW\", \"U300\", \"Guess\"]\n",
    "nModel = len(namearr)\n",
    "\n",
    "# Create a list of case names\n",
    "casearr = [\"Case A\", \"Case B\", \"Case C\", \"Case D\", \"Case E\"]\n",
    "nCase = len(casearr)\n",
    "\n",
    "# Create lists of colors, labels, and main titles\n",
    "colors = [\"red\", \"blue\", \"green\", \"magenta\", \"orange\"]\n",
    "labels = [\"Case A\", \"Case B\", \"Case C\", \"Case D\", \"Case E\"]\n",
    "maintitles = [\"DJF\", \"JJA\", \"MAM\", \"SON\"]\n",
    "\n",
    "# Generate one plot for each season\n",
    "for i in range(4):\n",
    "    # Create dummy data for the season\n",
    "    stddev = np.random.normal(1, 0.25, (nCase, nModel))\n",
    "    corrcoef = np.random.uniform(0.7, 1, (nCase, nModel))\n",
    "\n",
    "    # Create taylor diagram\n",
    "    da = gv.TaylorDiagram(fig=fig, rect=221 + i, label='REF')\n",
    "\n",
    "    # Add models case by case\n",
    "    for j in range(stddev.shape[0]):\n",
    "        da.add_model_set(stddev[j],\n",
    "                         corrcoef[j],\n",
    "                         xytext=(-4, 5),\n",
    "                         fontsize=10,\n",
    "                         color=colors[j],\n",
    "                         label=labels[j],\n",
    "                         marker='o')\n",
    "    # Add legend\n",
    "    da.add_legend(1.1, 1.05, fontsize=9, zorder=10)\n",
    "\n",
    "    # Set fontsize and pad\n",
    "    da.set_fontsizes_and_pad(11, 13, 2)\n",
    "\n",
    "    # Add title\n",
    "    da.add_title(maintitles[i], 14, 1.05)\n",
    "\n",
    "    # Add model names\n",
    "    da.add_model_name(namearr, x_loc=0.08, y_loc=0.4, fontsize=8)\n",
    "\n",
    "# Show the plot\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
